def cart_block(offset, block, damage=0, data={}): cmd = format("setblock ~ ~{offset} ~ {block} {dmg} replace", block=block, dmg=damage) if offset: cmd = format(cmd, offset=offset) else: cmd = format(cmd, offset="") if data: cmd = nbt.cmd(cmd, data, True) return cart(cmd)
def prettystr(self): return format("{cmd}{init}{cond}{repeat}", cmd=self.cmd, init="\n - Initialization" if self.init else "", cond="\n - Conditional" if self.cond else "", repeat="\n - Repeating" if self.block == "repeating_command_block" else "")
def gen_cart_stack(init_commands, clock_commands, mode, loud=False): final_command_obj = None if clock_commands or init_commands: entities = [] entities.append(sands.normal_sand("activator_rail")) for command in init_commands: if hasattr(command, "cmd"): if loud: color_print(command.prettystr()) entities.append(cart(command.cmd)) offset = 1 for command in clock_commands: if offset == 1: command.block = "repeating_command_block" if loud: color_print(command.prettystr()) entities.append(cart_command_block(offset, command, 1, mode)) offset += 1 filloffset = offset+1 offset += 2 entities.append(cart_command_block(offset, Command(format("clone ~ ~-2 ~ ~ ~-{o1} ~ ~ ~-{o2} ~ replace move", o1=offset-1,o2=offset+2)))) offset += 1 entities.append(cart_command_block(offset, Command(format("fill ~ ~-{o1} ~ ~ ~-{o2} ~ air", o1=offset,o2=offset+2)))) offset += 1 activatesand = sands.normal_sand("command_block") activatesand["TileEntityData"] = {"auto": 1} entities.append(cart_block(offset, "air")) entities.append(cart(nbt.cmd(format("summon falling_block ~ ~{o} ~ ", o=offset), activatesand, True))) entities.append(cart_command_block(filloffset, Command(format("fill ~ ~ ~ ~ ~{o} ~ air", o=offset-filloffset)))) entities.append(cart("kill @e[r=1,type=commandblock_minecart]")) stack = ride(entities) final_stack = sands.ride([ stack, sands.normal_sand("redstone_block"), sands.normal_sand("barrier") ], False) final_command_obj = nbt.cmd("summon falling_block ~ ~1 ~ ", final_stack) final_command = nbt.JSON2Command(final_command_obj) return final_command
def gen_cart_stack(init_commands, clock_commands, mode, loud=False): final_command_obj = None if clock_commands or init_commands: entities = [] entities.append(sands.normal_sand("activator_rail")) for command in init_commands: if hasattr(command, "cmd"): if loud: color_print(command.prettystr()) entities.append(cart(command.cmd)) offset = 1 for command in clock_commands: if offset == 1: command.block = "repeating_command_block" if loud: color_print(command.prettystr()) entities.append(cart_command_block(offset, command, 1, mode)) offset += 1 filloffset = offset + 1 offset += 2 entities.append( cart_command_block( offset, Command( format("clone ~ ~-2 ~ ~ ~-{o1} ~ ~ ~-{o2} ~ replace move", o1=offset - 1, o2=offset + 2)))) offset += 1 entities.append( cart_command_block( offset, Command( format("fill ~ ~-{o1} ~ ~ ~-{o2} ~ air", o1=offset, o2=offset + 2)))) offset += 1 activatesand = sands.normal_sand("command_block") activatesand["TileEntityData"] = {"auto": 1} entities.append(cart_block(offset, "air")) entities.append( cart( nbt.cmd(format("summon falling_block ~ ~{o} ~ ", o=offset), activatesand, True))) entities.append( cart_command_block( filloffset, Command( format("fill ~ ~ ~ ~ ~{o} ~ air", o=offset - filloffset)))) entities.append(cart("kill @e[r=1,type=commandblock_minecart]")) stack = ride(entities) final_stack = sands.ride([ stack, sands.normal_sand("redstone_block"), sands.normal_sand("barrier") ], False) final_command_obj = nbt.cmd("summon falling_block ~ ~1 ~ ", final_stack) final_command = nbt.JSON2Command(final_command_obj) return final_command
def gen_stack(init_commands, clock_commands, mode, loud=False): final_command_obj = None if clock_commands or init_commands: command_sands = [] repeatoffsets = [] if mode == 'i': if clock_commands and isinstance(clock_commands[0], Command): repeatoffsets.append(len(clock_commands) + 2) for command in clock_commands: if command.block == "repeating_command_block" and not command.cond and command is not clock_commands[ 0]: repeatoffsets.append( len(clock_commands) - clock_commands.index(command) + 2 + len(repeatoffsets)) filloffset = len(init_commands) + len(repeatoffsets) if filloffset: filloffset += 1 if filloffset: if loud: color_print("minecraft:command_block:0\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True) sand = normal_sand("command_block") if mode == 'i': sand["TileEntityData"] = {"auto": 1} command_sands.append(sand) for command in init_commands: if loud: color_print(command.prettystr(), allow_repeat=True) command_sands.append(generate_sand(command, 0)) for offset in repeatoffsets[::-1]: blockdata = Command(format("blockdata ~ ~-{offset} ~ {auto:1b}", offset=offset), init=True) if loud: color_print(blockdata.prettystr(), allow_repeat=True) sand = generate_sand(blockdata, 0) command_sands.append(sand) if filloffset: fill = Command(format("fill ~ ~-1 ~ ~ ~{offset} ~ air", offset=filloffset), init=True) if loud: color_print(fill.prettystr(), allow_repeat=True) color_print("minecraft:barrier\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True) command_sands.append(generate_sand(fill, 0)) command_sands.append(normal_sand("barrier")) for command in clock_commands[::-1]: if command is clock_commands[0] and isinstance(command, Command): command.block = "repeating_command_block" command_sands.append(generate_sand(command, 1)) else: sand = generate_sand(command, 1) if command.block == "repeating_command_block" and command.cond: sand["TileEntityData"]["auto"] = 1 command_sands.append(sand) if loud: color_print(command.prettystr(), allow_repeat=True) final_command_obj = nbt.cmd("summon falling_block ~ ~1 ~ ", ride(command_sands, False)) final_command = nbt.JSON2Command(final_command_obj) return final_command
def prettystr(self): return format("{darkgray}{block}{init}", block = self, init = "\n - Initialization" if self.init else "")
def __str__(self): return format("{block} {data}", block=self.block, data=self.data)
def prettystr(self): return format("{cmd}{init}{cond}{repeat}", cmd = self.cmd, init = "\n - Initialization" if self.init else "", cond = "\n - Conditional" if self.cond else "", repeat="\n - Repeating" if self.block == "repeating_command_block" else "")
def gen_stack(init_commands, clock_commands, mode, loud=False): final_command_obj = None if clock_commands or init_commands: command_sands = [] repeatoffsets = [] if mode == "i": if clock_commands and isinstance(clock_commands[0], Command): repeatoffsets.append(len(clock_commands) + 2) for command in clock_commands: if command.block == "repeating_command_block" and not command.cond and command is not clock_commands[0]: repeatoffsets.append(len(clock_commands) - clock_commands.index(command) + 2 + len(repeatoffsets)) filloffset = len(init_commands) + len(repeatoffsets) if filloffset: filloffset += 1 if filloffset: if loud: color_print( "minecraft:command_block:0\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True ) sand = normal_sand("command_block") if mode == "i": sand["TileEntityData"] = {"auto": 1} command_sands.append(sand) for command in init_commands: if loud: color_print(command.prettystr(), allow_repeat=True) command_sands.append(generate_sand(command, 0)) for offset in repeatoffsets[::-1]: blockdata = Command(format("blockdata ~ ~-{offset} ~ {auto:1b}", offset=offset), init=True) if loud: color_print(blockdata.prettystr(), allow_repeat=True) sand = generate_sand(blockdata, 0) command_sands.append(sand) if filloffset: fill = Command(format("fill ~ ~-1 ~ ~ ~{offset} ~ air", offset=filloffset), init=True) if loud: color_print(fill.prettystr(), allow_repeat=True) color_print("minecraft:barrier\n - Initialization", color=ansi_colors.DARKGRAY, allow_repeat=True) command_sands.append(generate_sand(fill, 0)) command_sands.append(normal_sand("barrier")) for command in clock_commands[::-1]: if command is clock_commands[0] and isinstance(command, Command): command.block = "repeating_command_block" command_sands.append(generate_sand(command, 1)) else: sand = generate_sand(command, 1) if command.block == "repeating_command_block" and command.cond: sand["TileEntityData"]["auto"] = 1 command_sands.append(sand) if loud: color_print(command.prettystr(), allow_repeat=True) final_command_obj = nbt.cmd("summon FallingSand ~ ~1 ~ ", ride(command_sands, False)) final_command = nbt.JSON2Command(final_command_obj) return final_command
def prettystr(self): return format("{darkgray}{block}{init}", block=self, init="\n - Initialization" if self.init else "")