Beispiel #1
0
 def align(self, axes: Union[axis, tuple]):
     if isinstance(axes, (list, tuple)):
         axes = "".join(translate(axis) for axis in axes)
     else:
         axes = translate(axes)
     self.output.append(f"align {translate(axes)}")
     return self
Beispiel #2
0
    def build(self):
        advancements, name, scores = None, None, None

        if self.advancements is not None:
            advancements = dict_to_advancement_selector(self.advancements)

        if self.name is not None:
            name = f"'{self.name}'"

        if self.scores is not None:
            scores = dict_to_score_selector(self.scores)

        output = []
        for key, item in vars(self).items():
            if item is not None and key != "type":
                if key in {
                        "gamemode", "level", "name", "tag", "team", "predicate"
                } and isinstance(item, list):
                    for arg in item:
                        output.append(f"{translate(key)}={translate(arg)}")
                # This awful special case needs to exist because overwriting the class attributes makes building the selector more than once error out, and copying, overwriting, appending to output, and rewriting the copy back to the class attribute is even worse
                elif key == "advancements" and advancements is not None:
                    output.append(
                        f"{translate(key)}={translate(advancements)}")
                elif key == "name" and name is not None:
                    output.append(f"{translate(key)}={translate(name)}")
                elif key == "scores" and scores is not None:
                    output.append(f"{translate(key)}={translate(scores)}")
                else:
                    output.append(f"{translate(key)}={translate(item)}")

        if output:
            return f"{translate(self.type)}[{', '.join(output)}]"
        else:
            return translate(self.type)
Beispiel #3
0
    def build(self):
        output = {}

        for key, item in vars(self).items():
            if item is not None:
                if key == "color":
                    if translate(item) == "pink":
                        item = "light_purple"
                    elif translate(item) == "purple":
                        item = "dark_purple"
                elif key == "extra":
                    item = self.extra.build(is_extra=True)
                elif key in {"click_event", "hover_event"}:
                    key = camelify(key)

                output[key] = translate(item)

        return output
Beispiel #4
0
 def __init__(self,
              action: hover_event_action = None,
              text: str = None,
              item_id: str = None,
              item_tags: dict = None):
     self.action = translate(action)
     self.text = text
     self.item_id = item_id
     self.item_tags = item_tags
Beispiel #5
0
    def __init__(self,
                 name: str,
                 create: bool = False,
                 criteria: str = "dummy",
                 display_name: str = None):
        self.name = name
        self.create = create
        self.criteria = criteria
        self.display_name = translate(display_name)

        if self.create == True:
            Commands.push(
                f"scoreboard objectives add {self.name} {self.criteria} {self.display_name}",
                init=True)

        # self.operator is overwritten if anything except "=" is used
        self.operator = "="

        # Used to keep track of existing players to de-dupe stuff
        self.players = {}
Beispiel #6
0
 def build(self):
     if self.action == "show_text":
         return {"action": "show_text", "contents": translate(self.text)}
     elif self.action == "show_item":
         if self.item_tags is not None:
             return {
                 "action":
                 "show_item",
                 "contents": ({
                     "id": self.item_id,
                     "count": Byte(1),
                     "tag": Compound(self.item_tags).snbt()
                 })
             }
         else:
             return {
                 "action": "show_item",
                 "contents": ({
                     "id": self.item_id,
                     "count": Byte(1)
                 })
             }
Beispiel #7
0
 def __init__(self, action: click_event_action, value: str):
     self.action = translate(action)
     self.value = value
Beispiel #8
0
 def __eq__(self, value: "Player"):
     if isinstance(value, Player):
         return Expression(str(self), "=", str(value))
     # Handles Range object as well
     else:
         return Expression(str(self), "matches", translate(value))