Skip to content

Commit

Permalink
Some Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aspirata committed Nov 16, 2024
1 parent 38143f8 commit 03a1a87
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
Binary file modified MiBlend.blend
Binary file not shown.
12 changes: 9 additions & 3 deletions MiBlend_Source/MIB_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def PBSDF_compability(Input: str) -> str:
def clamp(min_value, value, max_value):
return max(min_value, min(value, max_value))

def safe_check(condition):
try:
return condition
except:
return False

def convert_to_linux(path):
if sys.platform.startswith('linux'):
return path.replace("\\", "/")
Expand All @@ -41,15 +47,15 @@ def MaterialIn(Array, material, mode="in"):
def detect_obj_type(obj_name: str = "", mat_name: str = "") -> str:

if "item" in obj_name or "item" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "item":
dprint(f"{obj_name}; {mat_name} is an item")
#dprint(f"{obj_name}; {mat_name} is an item")
return "item"

elif "block" in obj_name or "block" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "block":
dprint(f"{obj_name}; {mat_name} is a block")
#dprint(f"{obj_name}; {mat_name} is a block")
return "block"

elif "entity" in obj_name or "entity" in mat_name or bpy.data.objects[obj_name].get("MiBlend ID", None) == "entity":
dprint(f"{obj_name}; {mat_name} is a entity")
#dprint(f"{obj_name}; {mat_name} is a entity")
return "entity"

dprint(f"{obj_name}; {mat_name} is unknown")
Expand Down
2 changes: 1 addition & 1 deletion MiBlend_Source/Materials/Materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def fix_world():
PBSDF = None
image_texture_node = None
lbcf_node = None
bfc_node = None
Texture_Animator = None
auvf_node = None
scene = bpy.context.scene
Expand Down Expand Up @@ -241,7 +242,6 @@ def fix_world():
material.node_tree.links.new(lbcf_node.outputs[0], PBSDF.inputs["Base Color"])

# Simple Biomes Support

if "fern" or "spruce" in texture_parts:
biome = "Taiga"
elif "dark" in texture_parts:
Expand Down
68 changes: 43 additions & 25 deletions MiBlend_Source/Resource_Packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,20 @@ def find_image(image_name: str, root_folder: str, obj_type: str = "unknown") ->
if "textures" not in dirpath:
continue

if obj_type == "unknown":
dprint(f"{image_name} is {obj_type}")
dprint(f"Switching to hybrid mode...")
if obj_type != "unknown":
#dprint(f"{image_name} is {obj_type} using texture filter...")
dirpath = os.path.join(dirpath, obj_type)
else:
dprint(f"{image_name} is {obj_type} using texture filter...")
#else:
#dprint(f"{image_name} is {obj_type}")
#dprint(f"Switching to hybrid mode...")

fast_image = os.path.join(dirpath, image_name)

if os.path.isfile(fast_image):
#dprint(f"{fast_image} is found")
return fast_image
#else:
#dprint(f"{fast_image} isn't found, searching for the {image_name}...")

if not os.path.exists(dirpath):
continue
Expand All @@ -157,38 +165,48 @@ def find_image(image_name: str, root_folder: str, obj_type: str = "unknown") ->
def zip_unpacker(root_folder: str, image_name: str, obj_type: str , file=None) -> Optional[str]:
extract_path = os.path.join(resource_packs_directory, os.path.splitext(file if file is not None else os.path.basename(root_folder))[0])
with zipfile.ZipFile(root_folder, 'r') as zip_ref:
infolist = zip_ref.infolist()
namelist = zip_ref.namelist()

if obj_type == "unknown":
dprint(f"{image_name} is {obj_type}")
dprint(f"Switching to hybrid mode...")
filtered_infolist = [item for item in infolist if f"textures" in item.filename]
#dprint(f"{image_name} is {obj_type}")
#dprint(f"Switching to hybrid mode...")
filtered_namelist = [item for item in namelist if f"textures" in item]
else:
dprint(f"{image_name} is {obj_type} using texture filter...")
filtered_infolist = [item for item in infolist if f"textures/{obj_type}" in item.filename]
#dprint(f"{image_name} is {obj_type} using texture filter...")
filtered_namelist = [item for item in namelist if f"textures/{obj_type}" in item]

infolist = filtered_infolist
namelist = filtered_namelist

fast_image = namelist[0].replace(os.path.basename(namelist[0]), image_name)
extracted_file_path = os.path.join(extract_path, fast_image)

if fast_image in namelist:
#dprint(f"{fast_image} is found")
if not os.path.isfile(os.path.join(extract_path, fast_image)):
zip_ref.extract(fast_image, extract_path)
return extracted_file_path
#else:
#dprint(f"{fast_image} isn't found, searching for the {image_name}...")

if r_props.animate_textures:
for zip_info in infolist:
if not zip_info.filename.endswith(".mcmeta"):
for zip_info in namelist:
if not zip_info.endswith(".mcmeta"):
continue

texture = os.path.basename(zip_info.filename).replace(".mcmeta", "")
extracted_file_path = os.path.join(extract_path, zip_info.filename)
texture = os.path.basename(zip_info).replace(".mcmeta", "")
extracted_file_path = os.path.join(extract_path, zip_info)

if (texture == image_name) or ("grass" in image_name and (texture == f"short_{image_name}" or texture == image_name.replace("short_", "") or file == image_name)) \
and not os.path.isfile(extracted_file_path):

zip_ref.extract(zip_info, extract_path)

for zip_info in infolist:
if not zip_info.filename.endswith(".png"):
for zip_info in namelist:
if not zip_info.endswith(".png"):
continue

texture = os.path.basename(zip_info.filename)
dprint(f"{texture} ; {image_name}")
extracted_file_path = os.path.join(extract_path, zip_info.filename)
texture = os.path.basename(zip_info)
extracted_file_path = os.path.join(extract_path, zip_info)

if (texture == image_name) or ("grass" in image_name and (texture == f"short_{image_name}" or texture == image_name.replace("short_", "") or file == image_name)):

Expand Down Expand Up @@ -586,9 +604,6 @@ def emission_texture_change(new_emission_image_path, emission_texture_node, PBSD
if not selected_object.material_slots:
Absolute_Solver("m003", selected_object)
continue

obj_type = None
obj_type = detect_obj_type(selected_object.name)

for slot, material in enumerate(selected_object.data.materials):
if material is None or not material.use_nodes:
Expand All @@ -614,6 +629,9 @@ def emission_texture_change(new_emission_image_path, emission_texture_node, PBSD
new_normal_image_path = None
new_specular_image_path = None

obj_type = None
obj_type = detect_obj_type(selected_object.name, material.name)

for node in material.node_tree.nodes:

if node.type == "BSDF_PRINCIPLED":
Expand Down Expand Up @@ -691,7 +709,7 @@ def emission_texture_change(new_emission_image_path, emission_texture_node, PBSD
path, Type, enabled = pack_info["path"], pack_info["type"], pack_info["enabled"]
if not enabled or "PBR" not in Type:
continue

if normal_texture_node is None:
normal_image_name = image_texture.replace(".png", "_n.png")
else:
Expand Down

0 comments on commit 03a1a87

Please sign in to comment.