Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resourcepack format version 22 short_grass and filtering out block models #643

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

zNightlord
Copy link
Contributor

Small fix on the grass format issue, haven't tested on JMC, Mineways so far MCprep default and Barebone 1.21 pack work. The "colormap/grass" isn't supposed to be there anyway, I think.

And filter out most of the no geometry json file, hope I didn't miss anything.

@zNightlord zNightlord requested review from StandingPadAnimations and a team and removed request for StandingPadAnimations December 17, 2024 18:33
@zNightlord
Copy link
Contributor Author

Just noticed the test with the colormap/grass issue.

diff --git a/MCprep_addon/materials/generate.py b/MCprep_addon/materials/generate.py
index 04a5e69..d10060d 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
@@ -220,6 +221,31 @@ 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"""
+       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 ame 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
+       return 21
+
+
 def detect_form(materials: List[Material]) -> Optional[Form]:
        """Function which, given the input materials, guesses the exporter form.

@@ -371,6 +397,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_packformat = get_format_version_texturepack(folder)
+       if (material.name == "grass" and texture_packformat > 21):
+               mc_name = "short_grass"
        image = find_from_texturepack(mc_name, folder)
        if isinstance(image, MCprepError):
                if image.msg:
                 ```
 Maybe a different approach rather changing the json file, checking the pack format version and condition from there.

@zNightlord zNightlord force-pushed the fix-model-grass-format-v22 branch from 5129366 to a719b64 Compare December 18, 2024 08:26
Copy link
Collaborator

@StandingPadAnimations StandingPadAnimations left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for the most part, though a couple of changes are needed.

One thing I think we may need more discussion on is how we should handle older pack formats. Generally, we include the newest resource pack at the time with the assets, which does open a can of worms with compatibility.

Comment on lines +242 to +243
# return the unaffected change version, 22
return 21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All pack.mcmeta files should define the pack format, so I wouldn't include this catch-all return 21. It could result in some silent errors.

I'd prefer an MCprepError object be returned if pack.mcmeta doesn't contain the pack format or if the file doesn't exist. To me at least, that's a bug with the resource pack.

A check for the pack and pack_format keys should also be added, just because there's no guarantee that either key will exist. I would have also suggested a TypedDict since pack.mcmeta has a well-defined structure, but I don't think Blender 2.8X has a new enough Python version for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of the current default MCprep resourcepack doesn't have the meta file and if you make it return like that this whole check_dirs part is considered as unnecessary, throw away the legacy behavior, you can swap any sub folder like from the "textures" folder can also work.

Comment on lines +399 to +400
if (material.name == "grass" and texture_pack_format > 21):
mc_name = "short_grass"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should extend this further to all changes, just to properly handle older resource packs, though I'll defer that decision to @TheDuckCow

Also, I think we should make sure that the OBJ actually needs this particular change. OBJs from worlds predating this change won't need us to handle pack format 22 compatibility, though checking might be a bit of a pain (this is making me wish CommonMCOBJ V1 included the world's version in the header, probably will open a proposal for that for V2 in the next couple of days)

MCprep_addon/materials/generate.py Outdated Show resolved Hide resolved
@zNightlord
Copy link
Contributor Author

zNightlord commented Dec 24, 2024

Think more on it, we can also introduce short_grass as it own block rather map it back to grass.
Since the problem comes from using pre 1.20.3 exporters which is "grass" and 1.20.3+ exporters would also have the "short_grass" to use.

EDIT: Additional gives warn based on versions detected "short_grass" or "grass" exists in the resourcepack but the materials has the opposite of "short_grass" or "grass".

@TheDuckCow
Copy link
Member

Think more on it, we can also introduce short_grass as it own block rather map it back to grass.

I'm ok with splitting things out more widely. The main consideration from my side is trying to keep parity as much as possible with the generated outputs of the mapping scripts below. Not sure if that influences anything here, I only lightly brushed up on the issue

https://github.com/Moo-Ack-Productions/MCprep/blob/master/mcprep_data_refresh.py

Which is used to generate the updates for:
https://github.com/Moo-Ack-Productions/MCprep/blob/master/MCprep_addon/MCprep_resources/mcprep_data_update.json

To avoid ever making manual changes to the above file, I do also have this base dictionary template below which is hand authored for special cases - so maybe that's an option here too, if we need to override some behavior and split something out:
https://github.com/Moo-Ack-Productions/MCprep/blob/master/mcprep_data_base.json

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per callout above, we want to modify the source mappings, not this file itself - otherwise it'll get overwritten directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants