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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion MCprep_addon/MCprep_resources/mcprep_data_update.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.

Original file line number Diff line number Diff line change
Expand Up @@ -4294,6 +4294,11 @@
0.614651,
0.089036
],
"short_grass": [
0.227161,
0.614651,
0.089036
],
"grass_block_side_overlay": [
0.227161,
0.614651,
Expand Down Expand Up @@ -4631,6 +4636,7 @@
"shulker_box",
"sunflower",
"water_still",
"water"
"water",
"conduit"
]
}
45 changes: 44 additions & 1 deletion MCprep_addon/materials/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -216,6 +217,39 @@ 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
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)
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
Comment on lines +249 to +250
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.



def detect_form(materials: List[Material]) -> Optional[Form]:
"""Function which, given the input materials, guesses the exporter form.

Expand Down Expand Up @@ -367,6 +401,15 @@ 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)
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"
Comment on lines +410 to +411
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)


image = find_from_texturepack(mc_name, folder)
if isinstance(image, MCprepError):
if image.msg:
Expand Down Expand Up @@ -588,7 +631,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):
Expand Down
14 changes: 13 additions & 1 deletion MCprep_addon/spawner/mcmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import json
import re
from mathutils import Vector
from math import sin, cos, radians
from pathlib import Path
Expand Down Expand Up @@ -456,7 +457,18 @@ 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:
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
Expand Down
1 change: 1 addition & 0 deletions mcprep_data_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions test_files/materials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading