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: cprint("minecraft:command_block:0\n - Initialization", color=bcolors.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: cprint(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: cprint(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: cprint(fill.prettystr(), allow_repeat=True) cprint("minecraft:barrier\n - Initialization", color=bcolors.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: cprint(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 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 load_line(chip, line): if line.startswith('CHIP['): pins = line[len('CHIP['):] pins = pins[:pins.find(']')] chip.pins = int(pins) name = line[line.find("'"):] if name[0] != "'" or name[len(name) - 1] != "'": error('name expected') chip.name = name[1:-1] elif line.startswith('POWER:'): power = line[len('POWER:'):].split(' ') for p in power: if len(p.strip()) == 0: continue if p[0] == '-': chip.powerMinus.append(int(p[1:])) elif p[0] == '+': chip.powerPlus.append(int(p[1:])) elif line.startswith('IN:'): inputs = line[len('IN:'):].split(',') for inp in inputs: name = inp.strip() if len(name) == 0: continue n = int(name) if n > chip.pins: error('wrong pin number ', n, ' for DIP-', chip.pins) chip.inputs.append(n) chip.currentInputs = chip.inputs elif line.startswith('OUT:'): outputs = line[len('OUT:'):].split(',') for out in outputs: name = out.strip() if len(name) == 0: continue if name[0] == '@': n = int(name[1:]) if n > chip.pins: error('wrong pin number ', n, ' for DIP-', chip.pins) chip.outputs.append(n) chip.pullUpOutputs.append(n) else: n = int(name) if n > chip.pins: error('wrong pin number ', n, ' for DIP-', chip.pins) chip.outputs.append(n) chip.currentOutputs = chip.outputs elif line.startswith('VOID:'): voids = line[len('VOID:'):].split(',') for v in voids: name = v.strip() if len(name) == 0: continue n = int(name) if n > chip.pins: error('wrong pin number ', n, ' for DIP-', chip.pins) sys.exit(-1) chip.void.append(n) elif line.startswith('SET:'): cmd = Command('set') sc = line[len('SET:'):].strip() if sc.find('->') > 0: lst = sc.split(';') for lsts in lst: itm = lsts.strip() level = itm.split('->')[0].strip() pins = itm.split('->')[1].strip() if level == '0': cmd.lst0 = str_to_int_list(pins) elif level == '1': cmd.lst1 = str_to_int_list(pins) else: error('invalid level ', level) else: sc = sc.replace(':', '') if len(sc) == len(chip.currentInputs): index = 0 list1 = '' list0 = '' for inp in chip.currentInputs: if sc[index] == '1': list1 = list1 + str(inp) + ',' elif sc[index] == '0': list0 = list0 + str(inp) + ',' else: error('wrong level ', sc[index]) index += 1 cmd.lst0 = str_to_int_list(list0) cmd.lst1 = str_to_int_list(list1) else: error('SET syntax error') chip.commands.append(cmd) elif line.startswith('TEST:'): cmd = Command('test') sc = line[len('TEST:'):].strip() if sc.find('->') > 0: lst = sc.split(';') for lsts in lst: itm = lsts.strip() pins = itm.split('->')[0].strip() level = itm.split('->')[1].strip() if level == '0': cmd.lst0 = str_to_int_list(pins) elif level == '1': cmd.lst1 = str_to_int_list(pins) else: error('invalid level ', level) elif sc.find('=>') > 0: cmd.name = 'set+test' # команда вида TEST: xxxx => yyyyyyyy args = sc.split('=>') from_val = args[0].strip().replace(':', '') to_val = args[1].strip().replace(':', '') if len(from_val) != len(chip.currentInputs): error('TEST syntax error - ', from_val) if len(to_val) != len(chip.currentOutputs): error('TEST syntax error -', to_val) index = 0 list1 = '' list0 = '' for inp in chip.currentInputs: if from_val[index] == '1': list1 = list1 + str(inp) + ',' elif from_val[index] == '0': list0 = list0 + str(inp) + ',' else: error('wrong level -', from_val[index]) index += 1 cmd.lst0 = str_to_int_list(list0) cmd.lst1 = str_to_int_list(list1) index = 0 list1 = '' list0 = '' for out in chip.currentOutputs: if to_val[index] == '1': list1 = list1 + str(out) + ',' elif to_val[index] == '0': list0 = list0 + str(out) + ',' else: error('wrong level - ', to_val[index]) index += 1 cmd.lst0_2 = str_to_int_list(list0) cmd.lst1_2 = str_to_int_list(list1) else: sc = sc.replace(':', '') if len(sc) == len(chip.currentOutputs): index = 0 list1 = '' list0 = '' for out in chip.currentOutputs: if sc[index] == '1': list1 = list1 + str(out) + ',' elif sc[index] == '0': list0 = list0 + str(out) + ',' else: error('wrong level - ', sc[index]) index += 1 cmd.lst0 = str_to_int_list(list0) cmd.lst1 = str_to_int_list(list1) else: error('TEST syntax error') chip.commands.append(cmd) elif line.startswith('PULSE:'): sc = line[len('PULSE:'):].strip() if sc[0] == '+': cmd = Command('pulse+') elif sc[0] == '-': cmd = Command('pulse-') else: error('wrong argument - ', sc) return cmd.pin = int(sc[1:].strip()) chip.commands.append(cmd) elif line.startswith("CONFIG:"): cmd = Command('config') sc = line[len('CONFIG:'):].strip() if sc.find('->') > 0: lst = sc.split(';') for lsts in lst: itm = lsts.strip() pins = itm.split('->')[0].strip() direct = itm.split('->')[1].strip() if direct == 'IN': cmd.lst0 = str_to_int_list(pins) elif direct == 'OUT': cmd.lst1 = str_to_int_list(pins) else: error('invalid direction ', direct) else: error('wrong syntax - ', sc) chip.commands.append(cmd) chip.currentInputs = cmd.lst0 chip.currentOutputs = cmd.lst1 elif line.startswith("TEST-Z"): cmd = Command('test-z') sc = line[len('TEST-Z:'):].strip() sc = sc.replace(':', '') if len(sc) == len(chip.currentOutputs): index = 0 listm = '' for inp in chip.currentOutputs: if sc[index] == '1': listm = listm + str(inp) + ',' elif sc[index] == '0': pass else: error('wrong mask ', sc[index]) index += 1 cmd.lst1 = str_to_int_list(listm) else: error('TEST-Z syntax error') chip.commands.append(cmd) elif line.startswith("TEST-OC"): cmd = Command('test-oc') sc = line[len('TEST-OC:'):].strip() sc = sc.replace(':', '') if len(sc) == len(chip.currentOutputs): index = 0 listm = '' for inp in chip.currentOutputs: if sc[index] == '1': listm = listm + str(inp) + ',' elif sc[index] == '0': pass else: error('wrong mask ', sc[index]) index += 1 cmd.lst1 = str_to_int_list(listm) else: error('TEST-OC syntax error') elif line.startswith("REPEAT-PULSE:"): cmd = Command('repeat-pulse') sc = line[len('REPEAT-PULSE:'):].strip() cmd.value = int(sc) chip.commands.append(cmd) else: error('wrong command - ', line) sys.exit(-1)