11from beet import Context , Model , NamespaceProxy , ListOption , ResourcePack
22from beet .contrib .vanilla import Vanilla , ClientJar
33from beet .contrib .optifine import OptifineProperties
4- from typing import Any , ClassVar , Literal , Optional
4+ from typing import Any , ClassVar , Literal
55from itertools import product , chain , count
66import re
77import logging
88from copy import deepcopy
99
10- from gm4 .plugins .resource_pack import ModelData , TemplateOptions , ItemModelOptions
10+ from gm4 .plugins .resource_pack import ModelData , TemplateOptions , JsonType
1111from gm4 .utils import add_namespace , MapOption
1212
1313parent_logger = logging .getLogger ("gm4." + __name__ )
@@ -63,15 +63,18 @@ class ShamirTemplate(TemplateOptions):
6363 textures_path : str = "" # directory of texture files to use for shamirs, falling back to the default metallurgy textures
6464 metal : Literal ["aluminium" , "barimium" , "barium" , "bismuth" , "curies_bismium" , "thorium" ] # the metallurgy metal this shamir is made of
6565
66+ _item_def_map : dict [str , JsonType ] = {}
67+ _model_overrides_1_21_3 : dict [str , list [JsonType ]] = {} # NOTE to be removed in 1.21.5
68+
6669 bound_ctx : ClassVar [Context ]
6770 metallurgy_assets : ClassVar [ResourcePack ] = ResourcePack (path = "gm4_metallurgy" ) # load metallurgy textures so expansion shamirs can fall back on their
6871 vanilla_models_jar : ClassVar [ClientJar ]
6972 vanilla_models_jar_1_21_3 : ClassVar [ClientJar ]
7073
71- def process (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
74+ def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
7275 logger = parent_logger .getChild (self .bound_ctx .project_id )
7376 models_loc = f"{ config .reference } "
74- models : dict [str , str | ItemModelOptions ] = {} # the value of config.models to be applied after going through special cases
77+ models : dict [str , str ] = {} # the value of config.models to be applied after going through special cases
7578 ret_list : list [Model ] = []
7679
7780 for item in config .item .entries ():
@@ -165,7 +168,7 @@ def recursive_extract_variants(json: dict[str, Any]) -> tuple[list[str], list[An
165168 itemdef_compound ["model" ] = variant_path # update our copy to point to the new model
166169
167170 # 1.21.3 Backwards Comparability - Remove in 1.21.5!
168- variants : Any = [{"model" : f"{ models_loc } /{ item } " }]
171+ variants : list [ JsonType ] = [{"model" : f"{ models_loc } /{ item } " }]
169172 for override in self .vanilla_models_jar_1_21_3 .assets .models [f"minecraft:item/{ item } " ].data .get ('overrides' , []):
170173 item_variant = override ['model' ].split ('/' )[- 1 ]
171174
@@ -175,7 +178,9 @@ def recursive_extract_variants(json: dict[str, Any]) -> tuple[list[str], list[An
175178 })
176179
177180 if item_variants :
178- models .update ({item : ComplexBypass (payload = mutatable_itemdef_copy , payload_1_21_3 = variants )})
181+ self ._item_def_map [item ] = mutatable_itemdef_copy
182+ self ._model_overrides_1_21_3 [item ] = variants
183+ models .update ({item : "NULL" }) # actual model paths contained within itemdef compound
179184 else :
180185 models .update ({item : f"{ models_loc } /{ item } " })
181186
@@ -209,6 +214,10 @@ def recursive_extract_variants(json: dict[str, Any]) -> tuple[list[str], list[An
209214 config .model = MapOption (__root__ = models )
210215 return ret_list
211216
217+ def get_item_def_entry (self , config : ModelData , item : str ) -> None | JsonType :
218+ # TODO fill me out, replacing ComplexBypass
219+ return self ._item_def_map .get (item )
220+
212221 def mutate_config (self , config : ModelData ):
213222 expanded_items = set (chain .from_iterable ([GROUP_LOOKUP .get (group , [group ]) for group in config .item .entries ()])) | {"player_head" }
214223 config .item = ListOption (__root__ = list (expanded_items ))
@@ -218,17 +227,6 @@ def mutate_config(self, config: ModelData):
218227 else : # isinstance(.., dict):
219228 config .textures = MapOption (__root__ = {"band" : f"gm4_metallurgy:item/band/{ self .metal } _band" }| config .textures .__root__ )
220229
221- class ComplexBypass (ItemModelOptions ):
222- """Generator for item model definitions on trimed armor, compasses with complex vanilla display conditions.
223- NOT INTENDED FOR USAGE IN CONFIG FILES. Used by config-mutating templates to pass item-model-def variants upstream to the file creation stage"""
224- # NOTE should this be in the base resource_pack file? Depends if any other modules use this approach
225- type = "_complex_bypass"
226- payload : dict [str , Any ]
227- payload_1_21_3 : Optional [Any ] = [] # NOTE backwards compatability field. Will be removed in 1.21.5 update
228-
229- def generate_json (self ) -> dict [str , Any ]:
230- return self .payload
231-
232230def optifine_armor_properties_merging (pack : ResourcePack , path : str , current : OptifineProperties , conflict : OptifineProperties ) -> bool :
233231 if not path .startswith ("gm4_metallurgy:cit" ): # only apply this rule to metallurgy files
234232 return False
0 commit comments