Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zNightlord committed Dec 18, 2024
1 parent 6514aa5 commit a719b64
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion MCprep_addon/MCprep_resources/mcprep_data_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -4631,6 +4631,7 @@
"shulker_box",
"sunflower",
"water_still",
"water"
"water",
"conduit"
]
}
34 changes: 33 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,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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 14 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,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
Expand Down

0 comments on commit a719b64

Please sign in to comment.