@@ -334,9 +334,6 @@ def beet_default(ctx: Context):
334334 VanillaTemplate .vanilla = Vanilla (ctx )
335335 VanillaTemplate .vanilla .minecraft_version = '1.21.4'
336336 VanillaTemplate .vanilla_jar = VanillaTemplate .vanilla .mount ("assets/minecraft/items" )
337- AdvancementIconTemplate .vanilla = Vanilla (ctx )
338- AdvancementIconTemplate .vanilla .minecraft_version = '1.21.4'
339- AdvancementIconTemplate .vanilla_jar = AdvancementIconTemplate .vanilla .mount ("assets/minecraft/items" )
340337
341338 yield
342339 tl .warn_unused_translations ()
@@ -975,34 +972,71 @@ class VanillaTemplate(TemplateOptions):
975972
976973 def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]):
977974 model_names = config .model .entries ()
978- if any ([isinstance (m , list ) for m in model_names ]):
979- raise InvalidOptions ("gm4.model_data" , f"{ config .reference } ; Template 'vanilla' does not support predicate override 'model' fields." )
980975 if len (set (model_names )) == 1 and len (config .item .entries ()) > 1 :
981976 model_names = [f"{ model_names [0 ]} _{ item } " for item in config .item .entries ()] # if only one model name given, make one model per item id
982977
983- model_def_entries = [
984- {
985- "type" : "minecraft:model" ,
986- "model" : m
987- }
988- for m in model_names ]
978+ model_def_map : dict [str ,JsonType ] = {}
989979
990980 ret_list : list [Model ] = []
991981 for item , model_name in zip (config .item .entries (), model_names ):
992982 model_compound = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {})
993983 if model_compound ["type" ] == "minecraft:special" : # uses some special handling
994984 vanilla_model_path : str = model_compound ["base" ] # covers player_head use case. Others may not be handled properly yet.
985+ special_model = True
995986 else :
996987 vanilla_model_path : str = model_compound .get ("model" , "" )
988+ special_model = False
997989 m = models_container [model_name ] = Model ({
998990 "parent" : vanilla_model_path
999991 })
1000992 ret_list .append (m )
1001- self ._item_def_map .update (dict (zip (config .item .entries (), model_def_entries )))
993+ model_def_map [item ] = {
994+ "type" : "minecraft:special" if special_model else "minecraft:model" ,
995+ "model" : model_compound ["model" ] if special_model else model_name
996+ } | (
997+ {"tints" : t if (t := model_compound .get ("tints" )) else {}}
998+ )
999+ self ._item_def_map .update (model_def_map )
10021000 return ret_list
10031001
10041002 def get_item_def_entry (self , config : ModelData , item : str ):
1005- return
1003+ return self ._item_def_map .get (item )
1004+
1005+ class AdvancementIconTemplate (VanillaTemplate , TemplateOptions ): # TODO make this inheritance work properly. Treat as single-vanilla forward or create new where needed
1006+ name = "advancement"
1007+ forward : Optional [str ]
1008+ tints : Optional [ListOption [int | tuple [float ,float ,float ]]] # optional constant tints to apply to the item model
1009+
1010+ # NOTE since advancements are all in the gm4 namespace, so are these models. This template ignores the 'model' field of ModelData
1011+ def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
1012+ advancement_name = config .reference .split ("/" )[- 1 ]
1013+ if not self .forward :
1014+ item = config .item .entries ()[0 ]
1015+ self .forward = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {}).get ("model" , "" ) # type: ignore ; json access is string
1016+
1017+ m = models_container [f"gm4:gui/advancements/{ advancement_name } " ] = Model ({
1018+ "parent" : self .forward
1019+ })
1020+ config .model = MapOption (__root__ = {config .item .entries ()[0 ]: f"gm4:gui/advancements/{ advancement_name } " })
1021+ return [m ]
1022+
1023+ def get_item_def_entry (self , config : ModelData , item : str ):
1024+ if self .tints :
1025+ return {
1026+ "type" : "model" ,
1027+ "model" : config .model .entries ()[0 ],
1028+ "tints" : [
1029+ {
1030+ "type" : "minecraft:constant" ,
1031+ "value" : tint
1032+ }
1033+ for tint in self .tints .entries ()
1034+ ]
1035+ }
1036+ return None
1037+
1038+ def add_namespace (self , namespace : str ):
1039+ return self .dict () | ({"forward" : add_namespace (self .forward , namespace )} if self .forward else {})
10061040
10071041class BlockTemplate (TemplateOptions ):
10081042 name = "block"
@@ -1022,7 +1056,7 @@ def create_models(self, config: ModelData, models_container: NamespaceProxy[Mode
10221056 }
10231057 })
10241058 return [m ]
1025-
1059+
10261060class ConditionTemplate (BlankTemplate , TemplateOptions ):
10271061 """Custom models using boolean condition variants (ie. broken/repaired elytra, cast/uncast fishing rods...)"""
10281062 name = "condition"
@@ -1048,45 +1082,6 @@ def add_namespace(self, namespace: str):
10481082 return self .dict () | {"on_true" : add_namespace (self .on_true , namespace ),
10491083 "on_false" : add_namespace (self .on_false , namespace )}
10501084
1051-
1052- class AdvancementIconTemplate (TemplateOptions ):
1053- name = "advancement"
1054- forward : Optional [str ]
1055- tints : Optional [ListOption [int | tuple [float ,float ,float ]]] # optional constant tints to apply to the item model
1056- vanilla : ClassVar [Vanilla ] # mounted to by beet plugin since it requires context access
1057- vanilla_jar : ClassVar [ClientJar ]
1058-
1059- # NOTE since advancements are all in the gm4 namespace, so are these models. This template ignores the 'model' field of ModelData
1060- def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
1061- advancement_name = config .reference .split ("/" )[- 1 ]
1062- if not self .forward :
1063- item = config .item .entries ()[0 ]
1064- self .forward = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {}).get ("model" , "" ) # type: ignore ; json access is string
1065-
1066- m = models_container [f"gm4:gui/advancements/{ advancement_name } " ] = Model ({
1067- "parent" : self .forward
1068- })
1069- config .model = MapOption (__root__ = {config .item .entries ()[0 ]: f"gm4:gui/advancements/{ advancement_name } " })
1070- return [m ]
1071-
1072- def get_item_def_entry (self , config : ModelData , item : str ):
1073- if self .tints :
1074- return {
1075- "type" : "model" ,
1076- "model" : config .model .entries ()[0 ],
1077- "tints" : [
1078- {
1079- "type" : "minecraft:constant" ,
1080- "value" : tint
1081- }
1082- for tint in self .tints .entries ()
1083- ]
1084- }
1085- return None
1086-
1087- def add_namespace (self , namespace : str ):
1088- return self .dict () | ({"forward" : add_namespace (self .forward , namespace )} if self .forward else {})
1089-
10901085class ItemDisplayModel (TransformOptions ):
10911086 """Calculates the model transform for an item_display entity, located at the specified origin, facing south, for the model to align with the block-grid"""
10921087 origin : list [float ] = Field (..., max_items = 3 , min_items = 3 )
0 commit comments