def upgrade(nbt: NBTCompound) -> NBTCompound: if 'ench' in nbt: nbt['Enchantments'] = nbt['ench'] del nbt['ench'] if 'Enchantments' in nbt: for ench in nbt['Enchantments']: ench['id'] = enchant.upgrade(ench['id']) if 'StoredEnchantments' in nbt: for ench in nbt['StoredEnchantments']: ench['id'] = enchant.upgrade(ench['id']) if 'CanDestroy' in nbt: for i in range(0, len(nbt['CanDestroy'])): nbt['CanDestroy'][i] = block.upgrade( ID(None, nbt['CanDestroy'][i].value), None, None, None)[0].value if 'CanPlaceOn' in nbt: for i in range(0, len(nbt['CanPlaceOn'])): nbt['CanPlaceOn'][i] = block.upgrade( ID(None, nbt['CanPlaceOn'][i].value), None, None, None)[0].value if 'BlockEntityTag' in nbt: nbt['BlockEntityTag'] = block_nbt.upgrade(nbt['BlockEntityTag']) if 'display' in nbt: if 'Name' in nbt['display']: nbt['display'][ 'Name'] = '\"\\"' + nbt['display']['Name'].value + '\\"\"' return nbt
def upgrade(id: ID, metadata: int, nbt: NBTCompound) -> str: if id.namespace: id.namespace = id.namespace.lower() if id.value: id.value = id.value.lower() if not metadata: metadata = 0 if nbt: # Process stuff that might be in NBT nbt = item_nbt.upgrade(nbt) if id.value in data.item_data_id_map: replacement_data = data.item_data_id_map[id.value] if type(replacement_data) is dict: id.value = data.item_data_id_map[id.value][metadata] else: id.value = replacement_data result = str(id) if nbt and nbt.values and len(nbt.values) > 0: result += str(nbt) return result
def upgrade(id: ID) -> str: if id.namespace: id.namespace = id.namespace.lower() if id.value: id.value = id.value.lower() if id.value in data.entity_id_map: id.value = data.entity_id_map[id.value] return str(id)
def __upgrade(order, props): # Hack to handle clear command if order[2] == 'clear': return 'effect clear ' + selector.upgrade(props['player']) new_selector = selector.upgrade(props['player']) new_id = effect.upgrade( props['id'].value if type(props['id']) is ID else props['id']) if type(props['id']) is ID: new_id = props['id'] new_id.value = effect.upgrade(new_id.value) else: new_id = ID(None, effect.upgrade(props['id'])) if 'duration' in props and props['duration'] <= 0: result = 'effect clear ' + new_selector + ' ' + str(new_id) else: result = 'effect give ' + new_selector + ' ' + str(new_id) + ' ' if 'duration' in props: result += str(props['duration']) + ' ' if 'amplifier' in props: result += str(props['amplifier']) + ' ' if len(order) == 6 and order[5] in ['true', 'false']: result += order[5] + ' ' if result[-1] == ' ': result = result[:-1] return result
def __merge(self, id_value: str, state: BlockState): if not self.res_id: self.res_id = ID(self.id.namespace, self.id.value) if not self.res_state: self.res_state = BlockState(dict()) if id_value: self.res_id.value = id_value if state: self.res_state.data.update(state.data)
def __set(self, id_value: str, state: BlockState): if not self.res_id: self.res_id = ID(self.id.namespace, self.id.value) if not self.res_state: self.res_state = BlockState(dict()) if id_value: self.res_id.value = id_value if state: self.res_state = state
def __init__(self, id: ID, state: BlockState, data: int, nbt: NBTCompound): self.id = id self.state = state self.data = data self.nbt = nbt if self.id.namespace: self.id.namespace = self.id.namespace.lower() if self.id.value: self.id.value = self.id.value.lower() self.res_id = ID(self.id.namespace, self.id.value) self.res_state = BlockState(self.state.data.copy( ) if self.state and self.state.data else dict()) self.res_nbt = None