From 34a9c980ad847c2e2cb24e2a5ab46e82044bea33 Mon Sep 17 00:00:00 2001 From: Jhon Tabio Date: Fri, 17 May 2024 02:59:03 -0400 Subject: [PATCH 1/2] Added 'entity' to yacc parser and entity -> entities in the loot_table_type types. This allows for the creation of entity loot tables --- compile.py | 2 +- global_context.py | 2 +- scriptlex.py | 4 ++-- scriptparse.py | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compile.py b/compile.py index 19fd57c..f8c533a 100644 --- a/compile.py +++ b/compile.py @@ -27,4 +27,4 @@ def run(): time.sleep(1) -run() \ No newline at end of file +run() diff --git a/global_context.py b/global_context.py index 74544ad..33ec758 100644 --- a/global_context.py +++ b/global_context.py @@ -198,4 +198,4 @@ def get_num_blocks(self): def get_num_block_states(self): blocks = self.get_block_state_list(True) - return len(blocks) \ No newline at end of file + return len(blocks) diff --git a/scriptlex.py b/scriptlex.py index d918408..faa0172 100644 --- a/scriptlex.py +++ b/scriptlex.py @@ -6,7 +6,7 @@ 'at', 'as', 'on', 'facing', 'rotated', 'align', 'here', 'the_end', 'the_nether', 'overworld', 'move', 'create', 'tell', 'title', 'subtitle', 'actionbar', 'reset', 'clock', 'function', 'if', 'unless', 'then', 'do', 'else', 'switch', 'case', 'default', - 'return', 'while', 'macro', 'block', 'block_data', 'block_tag', 'entity_tag', 'item_tag', 'define', 'array', 'remove', 'success', 'result', + 'return', 'while', 'macro', 'entity', 'block', 'block_data', 'block_tag', 'entity_tag', 'item_tag', 'define', 'array', 'remove', 'success', 'result', 'shaped', 'recipe', 'keys', 'eyes', 'feet', 'advancement', 'loot_table', 'predicate', "item_modifier", 'push', 'pop', 'true', 'false', ) @@ -159,4 +159,4 @@ def find_column(input, token): line_start = input.rfind('\n', 0, token.lexpos) + 1 return (token.lexpos - line_start) + 1 -lexer = lex.lex(debug=0) \ No newline at end of file +lexer = lex.lex(debug=0) diff --git a/scriptparse.py b/scriptparse.py index 9f7a414..69d3223 100644 --- a/scriptparse.py +++ b/scriptparse.py @@ -1818,9 +1818,11 @@ def p_advancement_definition(p): #### Loot Tables def p_loot_table_type(p): - '''loot_table_type : block''' + '''loot_table_type : block + | entity''' types = { 'block': 'blocks', + 'entity': 'entities', } if p[1] not in types: raise SyntaxError(f'Invalid loot table type "{p[1]}" at line {p.lineno(1)}.') @@ -1867,4 +1869,4 @@ def parse(data,debug=0): except SyntaxError as e: print(e) except Exception as e: - print(traceback.format_exc()) \ No newline at end of file + print(traceback.format_exc()) From e0b37ba40011ccb42eb9f88b3489dd8d9acc27e4 Mon Sep 17 00:00:00 2001 From: Jhon Tabio Date: Wed, 17 Jul 2024 23:44:19 -0400 Subject: [PATCH 2/2] Updated keywords/directory names to align with the Minecraft registry, same as what the 1.21+ update did --- mcworld.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mcworld.py b/mcworld.py index 6b0bef8..7c11ad5 100644 --- a/mcworld.py +++ b/mcworld.py @@ -24,7 +24,7 @@ def get_latest_log_file(self): return logfile def write_functions(self, functions): - function_dir = f'data/{self.namespace}/functions/' + function_dir = f'data/{self.namespace}/function/' for name in functions: filename = os.path.join(function_dir, f"{name}.mcfunction") @@ -34,7 +34,7 @@ def write_functions(self, functions): self.zip.writestr(filename, text) def write_tags(self, clocks, block_tags, entity_tags, item_tags): - tag_dir = 'data/minecraft/tags/functions/' + tag_dir = 'data/minecraft/tags/function/' tick_tag_file = os.path.join(tag_dir, 'tick.json') self.zip.writestr(tick_tag_file, json.dumps({'values':[f'{self.namespace}:{name}'for name in clocks]}, indent=4)) @@ -43,9 +43,9 @@ def write_tags(self, clocks, block_tags, entity_tags, item_tags): self.zip.writestr(load_tag_file, json.dumps({'values':[f'{self.namespace}:reset']}, indent=4)) for name, list in [ - ('blocks', block_tags), - ('items', item_tags), - ('entity_types', entity_tags) + ('block', block_tags), + ('item', item_tags), + ('entity_type', entity_tags) ]: if len(list) > 0: tag_dir = f'data/{self.namespace}/tags/{name}/' @@ -58,7 +58,7 @@ def write_tags(self, clocks, block_tags, entity_tags, item_tags): def write_recipes(self, recipes): if len(recipes) > 0: - recipe_dir = f'data/{self.namespace}/recipes/' + recipe_dir = f'data/{self.namespace}/recipe/' id = 0 for recipe in recipes: @@ -70,7 +70,7 @@ def write_recipes(self, recipes): def write_advancements(self, advancements): if len(advancements) > 0: - advancement_dir = f'data/{self.namespace}/advancements/' + advancement_dir = f'data/{self.namespace}/advancement/' for name in advancements: advancement_file = os.path.join(advancement_dir, f'{name}.json') @@ -84,17 +84,17 @@ def write_loot_tables(self, loot_tables): parts = name.split(':') if len(parts) != 2: raise CompileError(f'Invalid loot tables name "{name}"') - loot_table_dir = f'data/{parts[0]}/loot_tables/{type}/' + loot_table_dir = f'data/{parts[0]}/loot_table/{type}/' filename = parts[1] else: - loot_table_dir = f'data/{self.namespace}/loot_tables/{type}/' + loot_table_dir = f'data/{self.namespace}/loot_table/{type}/' filename = name loot_table_file = os.path.join(loot_table_dir, f'{filename}.json') self.zip.writestr(loot_table_file, contents) def write_predicates(self, predicates): if len(predicates) > 0: - predicate_dir = f'data/{self.namespace}/predicates/' + predicate_dir = f'data/{self.namespace}/predicate/' for name in predicates: predicate_file = os.path.join(predicate_dir, f'{name}.json') @@ -102,7 +102,7 @@ def write_predicates(self, predicates): def write_item_modifiers(self, item_modifiers): if len(item_modifiers) > 0: - item_modifier_dir = f'data/{self.namespace}/item_modifiers/' + item_modifier_dir = f'data/{self.namespace}/item_modifier/' for name in item_modifiers: item_modifier_file = os.path.join(item_modifier_dir, f'{name}.json')