Пример #1
0
    def handle_operator(self, name, value):
        if isinstance(value, int):
            if self.operator in {"=", "+=", "-="}:
                operator_name = {
                    "=": "set",
                    "+=": "add",
                    "-=": "remove"
                }[self.operator]
                return Commands.push(
                    f"scoreboard players {operator_name} {translate(name)} {self.name} {value}"
                )
            elif self.operator in {"*=", "/=", "%=", "<", ">"}:
                add_scoreboard("onyx.const"),
                Commands.push(
                    f"scoreboard players set ${value} onyx.const {value}",
                    init=True),
                return Commands.push(
                    f"scoreboard players operation {translate(name)} {self.name} {self.operator} ${value} onyx.const"
                )
            elif self.operator == "><":
                raise ValueError(
                    "Cannot swap between player score and integer")
        else:
            if self.operator in {
                    "=", "+=", "-=", "*=", "/=", "%=", "<", ">", "><"
            }:
                return Commands.push(
                    f"scoreboard players operation {translate(name)} {self.name} {self.operator} {value.name} {value.parent.name}"
                )

        self.operator = "="
Пример #2
0
 def __exit__(self, exception_type, exception_value, traceback):
     self.function_object.lines.extend(Commands.function_contents)
     Commands.pack_object.pack_object[
         self.new_function_path] = self.function_object
     Commands.function_contents = self.old_function_contents
     Commands.active_function = self.old_active_function
     Commands.push(
         f"execute {self.build()} run function {self.new_function_path}")
Пример #3
0
 def create(self, overwrite: bool = False):
     q = []
     if overwrite == True:
         q.append(
             Commands.push(f"scoreboard objectives remove {self.name}"))
     q.append(
         Commands.push(
             f"scoreboard objectives add {self.name} {self.criteria} {self.display_name}"
         ))
     return q
Пример #4
0
def add_scoreboard(objective, criteria="dummy"):
    from onyx.commands import Commands

    if objective not in Commands.added_scoreboards:
        Commands.added_scoreboards.append(objective)
        return Commands.push(
            f"scoreboard objectives add {objective} {criteria}", init=True)
Пример #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 = {}
Пример #6
0
    def __init__(self,
                 name: str,
                 path: str = None,
                 description: str = None,
                 version: int = 7):
        self.pack_data = {
            "name": name,
            "path": path,
            "description": description or 'Data Pack',
            "format": version
        }

        self.pack_object = beet.DataPack(self.pack_data["name"])
        self.pack_object.pack_format = self.pack_data["format"]
        self.pack_object.description = self.pack_data["description"]
        self.init_contents = []

        # Initalize the commands static class
        Commands(self)
Пример #7
0
 def run(self, command: Callable):
     return Commands.push(
         f"execute {self.build()} run {translate(command)}")
Пример #8
0
 def modify(self, trait: scoreboard_trait,
            value: Union[TextComponent, scoreboard_render_type]):
     return Commands.push(
         f"scoreboard objectives modify {self.name} {translate(trait)} {translate(value)}"
     )
Пример #9
0
 def setdisplay(self, display: scoreboard_display):
     return Commands.push(
         f"scoreboard objectives setdisplay {translate(display)} {self.name}"
     )
Пример #10
0
 def reset(self):
     return Commands.push(f"scoreboard players reset * {self.name}")
Пример #11
0
 def delete(self):
     return Commands.push(f"scoreboard objectives remove {self.name}")
Пример #12
0
 def reset(self):
     return Commands.push(
         f"scoreboard players reset {translate(self.name)} {self.parent.name}"
     )
Пример #13
0
 def enable(self):
     return Commands.push(
         f"scoreboard players enable {translate(self.name)} {self.parent.name}"
     )