Created
March 19, 2025 02:57
-
-
Save EvilSupahFly/488f3d80033523c42a76a365ba400333 to your computer and use it in GitHub Desktop.
resource_pack - __init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from typing import Iterable, Union | |
from minecraft_model_reader.api.resource_pack.base import (BaseResourcePack, BaseResourcePackManager,) | |
from minecraft_model_reader.api.resource_pack.java import (JavaResourcePack, JavaResourcePackManager,) | |
from minecraft_model_reader.api.resource_pack.bedrock import (BedrockResourcePack, BedrockResourcePackManager,) | |
from .unknown_resource_pack import UnknownResourcePack | |
# Define TRACE level before Amulet initializes logging | |
TRACE_LEVEL = 5 | |
logging.addLevelName(TRACE_LEVEL, "TRACE") | |
log = logging.getLogger(__name__) | |
if not log.handlers: | |
print("⚠️ WARNING: No log handlers found! Logging is broken.") | |
# Ensure TRACE-level logs are captured by Amulet’s setup | |
if log.level > TRACE_LEVEL: | |
log.setLevel(TRACE_LEVEL) | |
def load_resource_pack(resource_pack_path: str) -> BaseResourcePack: | |
log.trace(f"load_resource_pack: Resource Pack found: {resource_pack_path}") | |
if JavaResourcePack.is_valid(resource_pack_path): | |
#log.trace(f"load_resource_pack: Valid Java Pack found: {resource_pack_path}") | |
return JavaResourcePack(resource_pack_path) | |
elif BedrockResourcePack.is_valid(resource_pack_path): | |
#log.trace(f"load_resource_pack: Valid Bedrock Pack found: {resource_pack_path}") | |
return BedrockResourcePack(resource_pack_path) | |
else: | |
#log.trace(f"load_resource_pack: Unknown Pack found: {resource_pack_path}") | |
return UnknownResourcePack(resource_pack_path) | |
def load_resource_pack_manager(resource_packs: Iterable[Union[str, BaseResourcePack]], load: bool = True) -> BaseResourcePackManager: | |
log.trace(f"load_resource_pack_manager: Initial resource_packs = {resource_packs}") | |
resource_packs_out: list[BaseResourcePack] = [] | |
for resource_pack in resource_packs: | |
if isinstance(resource_pack, str): | |
log.trace(f"load_resource_pack: {resource_pack}") | |
resource_pack = load_resource_pack(resource_pack) | |
log.trace(f"load_resource_pack: Checking resource_pack - {resource_pack}") | |
log.trace(f"load_resource_pack:Checking , vars - {vars(resource_pack)}") | |
if (not isinstance(resource_pack, UnknownResourcePack) and resource_pack.valid_pack): | |
if resource_packs_out: | |
if isinstance(resource_pack, resource_packs_out[0].__class__): | |
resource_packs_out.append(resource_pack) | |
else: | |
resource_packs_out.append(resource_pack) | |
resource_packs = resource_packs_out | |
log.trace(f"DEBUG: Final selected resource packs: {resource_packs_out}") | |
if resource_packs: | |
if isinstance(resource_packs[0], JavaResourcePack): | |
return JavaResourcePackManager([pack for pack in resource_packs if isinstance(pack, JavaResourcePack)], load,) | |
elif isinstance(resource_packs[0], BedrockResourcePack): | |
return BedrockResourcePackManager([pack for pack in resource_packs if isinstance(pack, BedrockResourcePack)],load,) | |
raise NotImplementedError | |
# return UnknownResourcePackManager() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment