From a719b643839d5a1a796743af8bade1679aff6602 Mon Sep 17 00:00:00 2001 From: Trung <0znightlord0@gmail.com> Date: Wed, 18 Dec 2024 15:25:37 +0700 Subject: [PATCH 1/4] init --- .../MCprep_resources/mcprep_data_update.json | 3 +- MCprep_addon/materials/generate.py | 34 ++++++++++++++++++- MCprep_addon/spawner/mcmodel.py | 15 +++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/MCprep_addon/MCprep_resources/mcprep_data_update.json b/MCprep_addon/MCprep_resources/mcprep_data_update.json index bee49f90..31a93601 100644 --- a/MCprep_addon/MCprep_resources/mcprep_data_update.json +++ b/MCprep_addon/MCprep_resources/mcprep_data_update.json @@ -4631,6 +4631,7 @@ "shulker_box", "sunflower", "water_still", - "water" + "water", + "conduit" ] } \ No newline at end of file diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 5dc54375..2d4d5ac2 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -16,6 +16,7 @@ # # ##### END GPL LICENSE BLOCK ##### +import json import os from typing import Dict, Optional, List, Any, Tuple, Union, cast from pathlib import Path @@ -216,6 +217,33 @@ def find_from_texturepack(blockname: str, resource_folder: Optional[Path]=None) return res +def get_format_version_texturepack(resource_folder: Optional[Path]=None) -> Union[int, MCprepError]: + """ Get texturepack format version + + See https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats""" + if resource_folder is None: + # default to internal pack + resource_folder = Path(cast( + str, + bpy.path.abspath(bpy.context.scene.mcprep_texturepack_path) + )) + + if not resource_folder.exists() or not resource_folder.is_dir(): + env.log("Error, resource folder does not exist") + line, file = env.current_line_and_file() + return MCprepError(FileNotFoundError(), line, file, f"Resource pack folder at {resource_folder} does not exist!") + + # Resource folder is same level as assets folder + file = Path(resource_folder, "pack.mcmeta") + if (file.is_file()): + with open(file, 'r') as f: + data = json.load(f) + print(data) + return data["pack"]["pack_format"] + # return the unaffected change version, 22 + return 21 + + def detect_form(materials: List[Material]) -> Optional[Form]: """Function which, given the input materials, guesses the exporter form. @@ -367,6 +395,10 @@ def set_texture_pack( run the swap (and auto load e.g. normals and specs if avail.) """ mc_name, _ = get_mc_canonical_name(material.name) + texture_pack_format = get_format_version_texturepack(folder) + # grass rename to short_grass in MC 1.20.3 with pack format version 22 + if (material.name == "grass" and texture_pack_format > 21): + mc_name = "short_grass" image = find_from_texturepack(mc_name, folder) if isinstance(image, MCprepError): if image.msg: @@ -588,7 +620,7 @@ def get_textures(material: Material) -> Dict[str, Image]: def find_additional_passes(image_file: Path) -> Dict[str, Image]: """Find relevant passes like normal and spec in same folder as image.""" - print("What is this?", image_file) + # print("What is this?", image_file) # just gonna comment this out for now abs_img_file = bpy.path.abspath(str(image_file)) # needs to be blend file relative env.log(f"\tFind additional passes for: {image_file}", vv_only=True) if not os.path.isfile(abs_img_file): diff --git a/MCprep_addon/spawner/mcmodel.py b/MCprep_addon/spawner/mcmodel.py index dc71e3aa..95210853 100644 --- a/MCprep_addon/spawner/mcmodel.py +++ b/MCprep_addon/spawner/mcmodel.py @@ -18,6 +18,7 @@ import os import json +import re from mathutils import Vector from math import sin, cos, radians from pathlib import Path @@ -456,7 +457,19 @@ def update_model_list(context: Context): # Filter out models that can't spawn. Typically those that reference # #fire or the likes in the file. - if "template" in name: + # These blocks just don't make sense to put in the for "unspawnable_for_now" + # Template base of that block for example candle, cake with candles + # Orient blocks base, cube same as orientable (no texture) + # Light blocks are just special no geometry block with 15 states of light levels + # Shulkers, Hanging Signs, Signs are entities, put it here for now since they have a lot of variants + is_contains = re.search(r"template_|orientable|cube|_shulker_box|_sign|light_0|light_1", name) + if is_contains: + print(name) + continue + # Single word condition filter + # block single block parent, base parent of most MC contain gui displays + # Air, Barrier, Structure void has no geometry + if name in ["block", "air", "barrier", "structure_void"]: continue # Filter the "unspawnable_for_now" # Either entity block or block that doesn't good for json From d1eb1465f81a214ef9acb809f16ee7f79258db92 Mon Sep 17 00:00:00 2001 From: Trung <0znightlord0@gmail.com> Date: Wed, 18 Dec 2024 15:29:30 +0700 Subject: [PATCH 2/4] removing debug print --- MCprep_addon/materials/generate.py | 1 - MCprep_addon/spawner/mcmodel.py | 1 - 2 files changed, 2 deletions(-) diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 2d4d5ac2..88c70580 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -238,7 +238,6 @@ def get_format_version_texturepack(resource_folder: Optional[Path]=None) -> Unio if (file.is_file()): with open(file, 'r') as f: data = json.load(f) - print(data) return data["pack"]["pack_format"] # return the unaffected change version, 22 return 21 diff --git a/MCprep_addon/spawner/mcmodel.py b/MCprep_addon/spawner/mcmodel.py index 95210853..fd090562 100644 --- a/MCprep_addon/spawner/mcmodel.py +++ b/MCprep_addon/spawner/mcmodel.py @@ -464,7 +464,6 @@ def update_model_list(context: Context): # Shulkers, Hanging Signs, Signs are entities, put it here for now since they have a lot of variants is_contains = re.search(r"template_|orientable|cube|_shulker_box|_sign|light_0|light_1", name) if is_contains: - print(name) continue # Single word condition filter # block single block parent, base parent of most MC contain gui displays From 5a80a994c9f282bd95711679f7ce7f86525e4e94 Mon Sep 17 00:00:00 2001 From: Trung <0znightlord0@gmail.com> Date: Tue, 24 Dec 2024 20:37:09 +0700 Subject: [PATCH 3/4] adds mcmeta check --- MCprep_addon/materials/generate.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py index 88c70580..41188692 100644 --- a/MCprep_addon/materials/generate.py +++ b/MCprep_addon/materials/generate.py @@ -234,11 +234,18 @@ def get_format_version_texturepack(resource_folder: Optional[Path]=None) -> Unio return MCprepError(FileNotFoundError(), line, file, f"Resource pack folder at {resource_folder} does not exist!") # Resource folder is same level as assets folder - file = Path(resource_folder, "pack.mcmeta") - if (file.is_file()): - with open(file, 'r') as f: + meta_file = Path(resource_folder, "pack.mcmeta") + if meta_file.exists() and meta_file.is_file(): + with open(meta_file, 'r') as f: data = json.load(f) - return data["pack"]["pack_format"] + if data.get("pack"): + r = data.get("pack").get("pack_format") + if r: + return r + # Comment this out for now + # Invalid pack.mcmeta file + # line, file = env.current_line_and_file() + # MCprepError(TypeError(), line, file, f"Resource pack metadata ({meta_file}) is invalid!") # return the unaffected change version, 22 return 21 @@ -395,9 +402,14 @@ def set_texture_pack( """ mc_name, _ = get_mc_canonical_name(material.name) texture_pack_format = get_format_version_texturepack(folder) + if isinstance(texture_pack_format, MCprepError): + if texture_pack_format.msg: + env.log(texture_pack_format.msg) + return 0 # grass rename to short_grass in MC 1.20.3 with pack format version 22 if (material.name == "grass" and texture_pack_format > 21): mc_name = "short_grass" + image = find_from_texturepack(mc_name, folder) if isinstance(image, MCprepError): if image.msg: From c945d35f61931608662ebb97fcb4728eb9017247 Mon Sep 17 00:00:00 2001 From: Trung <0znightlord0@gmail.com> Date: Tue, 24 Dec 2024 21:49:27 +0700 Subject: [PATCH 4/4] short_grass saturation --- MCprep_addon/MCprep_resources/mcprep_data_update.json | 5 +++++ mcprep_data_base.json | 1 + test_files/materials_test.py | 1 + 3 files changed, 7 insertions(+) diff --git a/MCprep_addon/MCprep_resources/mcprep_data_update.json b/MCprep_addon/MCprep_resources/mcprep_data_update.json index 31a93601..a89f042a 100644 --- a/MCprep_addon/MCprep_resources/mcprep_data_update.json +++ b/MCprep_addon/MCprep_resources/mcprep_data_update.json @@ -4294,6 +4294,11 @@ 0.614651, 0.089036 ], + "short_grass": [ + 0.227161, + 0.614651, + 0.089036 + ], "grass_block_side_overlay": [ 0.227161, 0.614651, diff --git a/mcprep_data_base.json b/mcprep_data_base.json index 18ef19ff..c926e2c2 100644 --- a/mcprep_data_base.json +++ b/mcprep_data_base.json @@ -36,6 +36,7 @@ "desaturated":{ "vine": [0.227161, 0.614651, 0.089036], "grass": [0.227161, 0.614651, 0.089036], + "short_grass": [0.227161, 0.614651, 0.089036], "colormap/grass": [0.227161, 0.614651, 0.089036], "lily_pad": [0.227161, 0.614651, 0.089036], "attached_melon_stem": [0.227161, 0.614651, 0.089036], diff --git a/test_files/materials_test.py b/test_files/materials_test.py index 815fddad..936a3ab2 100644 --- a/test_files/materials_test.py +++ b/test_files/materials_test.py @@ -342,6 +342,7 @@ def test_detect_desaturated_images(self): should_saturate = { # Sample of canonically grayscale textures. "grass": True, + "short_grass": True, "grass_block_top": True, "acacia_leaves": True, "redstone_dust_line0": True,