def split_anvil_state(state_path): logger.info("Splitting the anvil states...") try: with open(f'{state_path}/anvil.json', 'r') as f: anvil_dict = json.loads("\n".join(modify_json(f))) if 'damage=0,facing=south' in anvil_dict['variants']: anvil_json = { 'variants': { "facing=south": anvil_dict['variants']["damage=0,facing=south"], "facing=west": anvil_dict['variants']["damage=0,facing=west"], "facing=north": anvil_dict['variants']["damage=0,facing=north"], "facing=east": anvil_dict['variants']["damage=0,facing=east"] } } with open(f'{state_path}/anvil.json', 'w') as dump_f: json.dump(anvil_json, dump_f) if 'damage=1,facing=south' in anvil_dict['variants']: chipped_anvil_json = { 'variants': { "facing=south": anvil_dict['variants']["damage=1,facing=south"], "facing=west": anvil_dict['variants']["damage=1,facing=west"], "facing=north": anvil_dict['variants']["damage=1,facing=north"], "facing=east": anvil_dict['variants']["damage=1,facing=east"] } } with open(f'{state_path}/chipped_anvil.json', 'w') as dump_f: json.dump(chipped_anvil_json, dump_f) if 'damage=2,facing=south' in anvil_dict['variants']: damaged_anvil_json = { 'variants': { "facing=south": anvil_dict['variants']["damage=2,facing=south"], "facing=west": anvil_dict['variants']["damage=2,facing=west"], "facing=north": anvil_dict['variants']["damage=2,facing=north"], "facing=east": anvil_dict['variants']["damage=2,facing=east"] } } with open(f'{state_path}/damaged_anvil.json', 'w') as dump_f: json.dump(damaged_anvil_json, dump_f) except IOError as e: logger.error(f"Failed to split anvil state because {e}")
def split_torch_states(state_path, prefix): logger.info(f"Splitting {prefix}torch states...") try: with open(f'{state_path}/{prefix}torch.json', 'r', encoding="utf-8") as f: torch_dict = json.loads("\n".join(modify_json(f))) if 'facing=up' in torch_dict['variants']: torch_json = { 'variants': { "": torch_dict['variants']["facing=up"] } } # print(torch_json) with open(f'{state_path}/{prefix}torch.json', 'w') as dump_f: json.dump(torch_json, dump_f) if 'facing=east' in torch_dict['variants']: if 'facing=up' in torch_dict['variants']: del torch_dict['variants']["facing=up"] wall_torch_json = torch_dict # print(wall_torch_json) with open(f'{state_path}/{prefix}wall_torch.json', 'w') as dump_f: json.dump(wall_torch_json, dump_f) except IOError as e: logger.error(f"Failed to split {prefix}torch states because {e}")
def change_info(pack_path, pack_format, description): """ Replace the pack format :param pack_path: :param pack_format: :param description: :return: """ logger.info("Changing pack format...") # Read the current data in # Then replace the format and description with open(f'{pack_path}/pack.mcmeta', 'r') as f: pack_info = json.loads("\n".join(modify_json(f))) pack_info['pack']['pack_format'] = pack_format if description != "": logger.info("Changing pack description...") pack_info['pack']['description'] = description # Write the new data with open(f'{pack_path}/pack.mcmeta', 'w') as f: json.dump(pack_info, f, ensure_ascii=False, indent=4)
def replace_anvil_textures(model_path): logger.info(f"Replacing the anvil textures...") anvil = f'{model_path}/block/anvil.json' anvil_undamaged = f'{model_path}/block/anvil_undamaged.json' if os.path.exists(anvil): with open(anvil, 'r') as f: anvil_json = json.loads("\n".join(modify_json(f))) if os.path.exists(anvil_undamaged): with open(anvil_undamaged, 'r') as f: anvil_tex = json.loads("\n".join(modify_json(f)))['textures'] else: anvil_tex = { "particle": "block/anvil", "body": "block/anvil", "top": "block/anvil_top" } anvil_json['textures'] = anvil_tex with open(anvil, 'w') as dump_f: json.dump(anvil_json, dump_f)
def replace_lever_variants(state_path): logger.info("Replacing lever variants...") try: with open(f'{state_path}/lever.json', 'r') as f: lever_dict = json.loads("\n".join(modify_json(f))) variants = {} variants = change_lever_variants(variants, lever_dict, 'false') variants = change_lever_variants(variants, lever_dict, 'true') with open(f'{state_path}/lever.json', 'w') as dump_f: json.dump({'variants': variants}, dump_f) except IOError as e: logger.error(f"Failed to replace lever variants because {e}")
def blockstate_fix_normal_variants(texture_path, model_path, state_path): """ In 1.8, blockstates have a "normal" variant. This was changed to "" in newer packs :param texture_path: :param model_path: :param state_path: :return: """ logger.info("Replacing blockstate normal variants") natural_texture_blocks = [ "bedrock", "dirt", "grass_path", "netherrack", "red_sand", "sand", "stone" ] for n in natural_texture_blocks: path = f'{state_path}/{n}.json' try: with open(path, 'r') as f: nblockdict = json.loads("\n".join(modify_json(f))) variants = nblockdict["variants"] newvar = variants["normal"] del variants["normal"] variants[""] = newvar with open(path, 'w') as dump_f: json.dump({'variants': variants}, dump_f) logger.debug(f"Converted {n}.json") except (IOError, KeyError) as e: logger.error(f"Failed because of {e}") os.remove(f"{state_path}/furnace.json") os.remove(f"{model_path}/block/item_frame.json") # TODO: Convert to a dictionary animated_blocks = [ ["furnace_front_on", 10], ["sea_lantern", 5] ] for block in animated_blocks: try: with open(f"{texture_path}/block/{block[0]}.png.mcmeta", 'w+') as dump_f: json.dump( { "animation": { "interpolate": True, "frametime": block[1] } }, dump_f ) logger.debug(f"Converted {block[0]}.png.mcmeta") except (IOError, KeyError) as e: logger.error(f"Failed because of {e}")
def merge_grass_block_models(model_path): logger.info(f"Merging the grass_block and grass_normal models...") grass_block = f'{model_path}/block/grass_block.json' grass_normal = f'{model_path}/block/grass_normal.json' if os.path.exists(grass_block): with open(grass_block, 'r') as f: grass_block_json = json.loads("\n".join(f)) # TODO: Move this to a specific files in a resource path if 'elements' not in grass_block_json: grass_block_json['elements'] = [{ "from": [0, 0, 0], "to": [16, 16, 16], "faces": { "down": { "uv": [0, 0, 16, 16], "texture": "#bottom", "cullface": "down" }, "up": { "uv": [0, 0, 16, 16], "texture": "#top", "cullface": "up", "tintindex": 0 }, "north": { "uv": [0, 0, 16, 16], "texture": "#side", "cullface": "north" }, "south": { "uv": [0, 0, 16, 16], "texture": "#side", "cullface": "south" }, "west": { "uv": [0, 0, 16, 16], "texture": "#side", "cullface": "west" }, "east": { "uv": [0, 0, 16, 16], "texture": "#side", "cullface": "east" } } }, { "from": [0, 0, 0], "to": [16, 16, 16], "faces": { "north": { "uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 0, "cullface": "north" }, "south": { "uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 0, "cullface": "south" }, "west": { "uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 0, "cullface": "west" }, "east": { "uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": 0, "cullface": "east" } } }] if os.path.exists(grass_normal): with open(grass_normal, 'r') as f: grass_normal_json = json.loads("\n".join(modify_json(f))) if "textures" in grass_block_json: grass_block_tex = grass_normal_json["textures"] else: grass_block_tex = grass_block_json["textures"] else: grass_block_tex = grass_block_json["textures"] # Replace textures if "particle" not in grass_block_tex: grass_block_tex["particle"] = "block/dirt" if "bottom" not in grass_block_tex: grass_block_tex["bottom"] = "block/dirt" if "top" not in grass_block_tex: grass_block_tex["top"] = "block/grass_block_top" if "side" not in grass_block_tex: grass_block_tex["side"] = "block/grass_block_side" if "overlay" not in grass_block_tex: grass_block_tex["overlay"] = "block/grass_block_side_overlay" grass_block_json["textures"] = grass_block_tex grass_block_json["parent"] = "block/block" with open(grass_block, 'w') as dump_f: json.dump(grass_block_json, dump_f)