def __init__(self, data): if 'cases' in data['options']: for key, val in data['options']['cases'].items(): data['options']['cases'][key] = FunctionList(val) if 'default' in data['options']: data['options']['default'] = FunctionList(data['options']['default']) BaseTranslationFunction.__init__(self, data)
def __init__(self, data: Dict[str, Union[dict, FunctionList, Dict[str, FunctionList]]]): for key in ('to_universal', 'blockstate_to_universal'): if key in data: data[key] = FunctionList(data[key]) for key in ('from_universal', 'blockstate_from_universal'): if key in data: for key_ in data[key]: data[key][key_] = FunctionList(data[key][key_]) self._data = data
def __init__(self, data, bypass_type=False): for key in ('self_default', 'functions'): if key in data: data[key] = FunctionList(data[key]) if not bypass_type and data['type'] in ('compound', 'list', 'byte_array', 'int_array', 'long_array'): if 'nested_default' in data: data['nested_default'] = FunctionList(data['nested_default']) if data['type'] == 'compound': if 'keys' in data: for key, val in data['keys'].items(): data['keys'][key] = ContainerWalkInputNBT(val) elif data['type'] == 'list': if 'index' in data: for key, val in data['index'].items(): data['index'][key] = ContainerWalkInputNBT(val) else: if 'index' in data: for key, val in data['index'].items(): data['index'][key] = ContainerWalkInputNBT(val, True) BaseTranslationFunction.__init__(self, data) self.bypass_type = bypass_type
def _pad_from_universal(self): # ensure that every state in the universal format gets mapped to something for key, fun in disk_buffer.translations['from_universal'].items(): if len(key) == 6 and key[0] == self.version_name and key[1] == 'block' and isinstance(fun, FunctionList) and not any(isinstance(sub_fun, NewBlock) for sub_fun in fun.function_list): log_to_file(f"Missing default block in {key}") fun.function_list.insert( 0, NewBlock( { "function": "new_block", "options": "minecraft:air" } ) ) # (version_name, object_type, version_format, namespace, group_name, base_name) if self.version_name != 'universal': for key in disk_buffer.files_to_save: if len(key) == 8 and key[0:5] == ('versions', 'universal', 'block', 'blockstate', "specification"): for version_format in ['numerical', 'blockstate']: if version_format == 'numerical' and self.block_format not in ["numerical", "pseudo-numerical"]: continue if (self.version_name, 'block', version_format, key[5], 'vanilla', key[7]) not in disk_buffer.translations['from_universal']: disk_buffer.translations['from_universal'][(self.version_name, 'block', version_format, key[5], 'vanilla', key[7])] = FunctionList([ { "function": "new_block", "options": "minecraft:air" } ])
def __init__(self, data): for option, data_ in data['options'].items(): data['options'][option] = FunctionList(data_) BaseTranslationFunction.__init__(self, data)
def _build_blocks(self): blocks_from_server(self._directory, [str(v) for v in self.version]) blocks_path = os.path.join(self._directory, 'generated', 'reports', 'blocks.json') if os.path.isfile(blocks_path): waterloggable = [] add = {} remove = {} for (namespace, sub_name), block_data in self.blocks.items(): remove.setdefault(namespace, set()) add.setdefault((namespace, sub_name), {}) for block_base_name, primitive_data in block_data.items(): if primitive_data is None: continue remove[namespace].add(block_base_name) add[(namespace, sub_name)][block_base_name] = primitives.get_block( self.primitive_block_format, primitive_data) # load the block list the server created blocks: dict = load_json_file(blocks_path) parent_blocks_path = os.path.join(self._directory, '..', self._parent_name, 'generated', 'reports', 'blocks.json') if os.path.isfile(parent_blocks_path) and not os.path.isfile( os.path.join(self._directory, 'changes.json')): parent_blocks = load_json_file(parent_blocks_path) with open(os.path.join(self._directory, 'changes.json'), 'w') as f: json.dump(find_blocks_changes(parent_blocks, blocks), f, indent=4) # unpack all the default states from blocks.json and create direct mappings unless that block is in the modifications for block_string, states in blocks.items(): namespace, block_base_name = block_string.split(':', 1) default_state = next(s for s in states['states'] if s.get('default', False)) if 'properties' in default_state: states['defaults'] = {} for key, val in default_state['properties'].items(): states['defaults'][key] = f"\"{val}\"" for prop, vals in states['properties'].items(): states['properties'][prop] = [ f"\"{val}\"" for val in vals ] if 'waterlogged' in states['properties']: if block_string not in waterloggable: waterloggable.append(block_string) del states['properties']['waterlogged'] del states['defaults']['waterlogged'] del states['states'] disk_buffer.add_specification(self.version_name, 'block', 'blockstate', namespace, 'vanilla', block_base_name, states) if not (namespace in remove and block_base_name in remove[namespace]): # the block is not marked for removal if 'properties' in default_state: to_universal = FunctionList( [{ "function": "new_block", "options": f"universal_{block_string}" }, { "function": "carry_properties", "options": states['properties'] }], True) from_universal = FunctionList( [{ "function": "new_block", "options": block_string }, { "function": "carry_properties", "options": states['properties'] }], True) else: to_universal = FunctionList( [{ "function": "new_block", "options": f"universal_{block_string}" }], True) from_universal = FunctionList([{ "function": "new_block", "options": block_string }], True) disk_buffer.add_translation_to_universal( self.version_name, 'block', 'blockstate', namespace, 'vanilla', block_base_name, to_universal) disk_buffer.add_translation_from_universal( self.version_name, 'block', 'blockstate', f'universal_{namespace}', 'vanilla', block_base_name, from_universal) # add in the modifications for blocks for namespace, sub_name in add: for block_base_name, block_data in add[(namespace, sub_name)].items(): if disk_buffer.has_translation_to_universal( self.version_name, 'block', 'blockstate', namespace, sub_name, block_base_name): print(f'"{block_base_name}" is already present.') else: if 'specification' in block_data: specification = block_data["specification"] if 'properties' in specification: if 'waterlogged' in specification[ 'properties']: if f'{namespace}:{block_base_name}' not in waterloggable: waterloggable.append( f'{namespace}:{block_base_name}') del specification['properties'][ 'waterlogged'] del specification['defaults'][ 'waterlogged'] elif disk_buffer.has_specification( self.version_name, 'block', 'blockstate', namespace, sub_name, block_base_name): gen_spec = disk_buffer.get_specification( self.version_name, 'block', 'blockstate', namespace, sub_name, block_base_name) if 'properties' in gen_spec: specification['properties'] = gen_spec[ 'properties'] specification['defaults'] = gen_spec[ 'defaults'] disk_buffer.add_specification( self.version_name, 'block', 'blockstate', namespace, sub_name, block_base_name, specification) assert 'to_universal' in block_data, f'"to_universal" must be present. Was missing for {self.version_name} {namespace}:{block_base_name}' disk_buffer.add_translation_to_universal( self.version_name, 'block', 'blockstate', namespace, sub_name, block_base_name, block_data["to_universal"]) assert 'from_universal' in block_data, f'"to_universal" must be present. Was missing for {self.version_name} {namespace}:{block_base_name}' for block_string2, mapping in block_data[ 'from_universal'].items(): namespace2, base_name2 = block_string2.split( ':', 1) try: disk_buffer.add_translation_from_universal( self.version_name, 'block', 'blockstate', namespace2, 'vanilla', base_name2, mapping) except Exception as e: print(self.version_name, namespace, block_base_name, namespace2, base_name2) raise Exception(e) disk_buffer.save_json_object( ('versions', self.version_name, '__waterloggable__'), waterloggable) disk_buffer.save_json_object( ('versions', self.version_name, '__always_waterlogged__'), self.always_waterlogged) else: raise Exception( f'Could not find {self.version_name}/generated/reports/blocks.json' )
def __init__(self, data): if isinstance(data['options'], dict): data['options'] = [data['options']] for option in data['options']: option['functions'] = FunctionList(option['functions']) BaseTranslationFunction.__init__(self, data)
def __init__(self, data): for property_name in data.get('options', {}): for property_value in data['options'][property_name]: data['options'][property_name][property_value] = FunctionList( data['options'][property_name][property_value]) BaseTranslationFunction.__init__(self, data)
import traceback import copy from typing import Union, List, Dict, Set from PyMCTCompiler.translation_functions.base_translation_function import FunctionList from PyMCTCompiler.primitives import _load_file print('Loading Nested Primitives ...') nested_primitives: Dict[str, FunctionList] = {} for root, _, files in os.walk(f'{os.path.dirname(__file__)}/data'): for f in files: primitive_name = os.path.splitext(f)[0] if primitive_name in nested_primitives: print(f'nested primitive "{primitive_name}" is define twice') try: nested_primitives[primitive_name] = FunctionList( _load_file(f'{root}/{f}')) except Exception as e: print(f'Failed to load {root}/{f}\n{e}') print(traceback.print_tb(e.__traceback__)) print('\tFinished Loading Nested Primitives') def _recursive_to_tuple(data): if isinstance(data, list): return tuple(_recursive_to_tuple(d) for d in data) else: return data def get(primitive_group: Union[str, List[str], List[List[str]]],