@@ -332,9 +332,6 @@ def beet_default(ctx: Context):
332332 VanillaTemplate .vanilla = Vanilla (ctx )
333333 VanillaTemplate .vanilla .minecraft_version = '1.21.5'
334334 VanillaTemplate .vanilla_jar = VanillaTemplate .vanilla .mount ("assets/minecraft/items" )
335- AdvancementIconTemplate .vanilla = Vanilla (ctx )
336- AdvancementIconTemplate .vanilla .minecraft_version = '1.21.4'
337- AdvancementIconTemplate .vanilla_jar = AdvancementIconTemplate .vanilla .mount ("assets/minecraft/items" )
338335
339336 yield
340337 tl .warn_unused_translations ()
@@ -891,34 +888,71 @@ class VanillaTemplate(TemplateOptions):
891888
892889 def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]):
893890 model_names = config .model .entries ()
894- if any ([isinstance (m , list ) for m in model_names ]):
895- raise InvalidOptions ("gm4.model_data" , f"{ config .reference } ; Template 'vanilla' does not support predicate override 'model' fields." )
896891 if len (set (model_names )) == 1 and len (config .item .entries ()) > 1 :
897892 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
898893
899- model_def_entries = [
900- {
901- "type" : "minecraft:model" ,
902- "model" : m
903- }
904- for m in model_names ]
894+ model_def_map : dict [str ,JsonType ] = {}
905895
906896 ret_list : list [Model ] = []
907897 for item , model_name in zip (config .item .entries (), model_names ):
908898 model_compound = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {})
909899 if model_compound ["type" ] == "minecraft:special" : # uses some special handling
910900 vanilla_model_path : str = model_compound ["base" ] # covers player_head use case. Others may not be handled properly yet.
901+ special_model = True
911902 else :
912903 vanilla_model_path : str = model_compound .get ("model" , "" )
904+ special_model = False
913905 m = models_container [model_name ] = Model ({
914906 "parent" : vanilla_model_path
915907 })
916908 ret_list .append (m )
917- self ._item_def_map .update (dict (zip (config .item .entries (), model_def_entries )))
909+ model_def_map [item ] = {
910+ "type" : "minecraft:special" if special_model else "minecraft:model" ,
911+ "model" : model_compound ["model" ] if special_model else model_name
912+ } | (
913+ {"tints" : t if (t := model_compound .get ("tints" )) else {}}
914+ )
915+ self ._item_def_map .update (model_def_map )
918916 return ret_list
919917
920918 def get_item_def_entry (self , config : ModelData , item : str ):
921- return
919+ return self ._item_def_map .get (item )
920+
921+ class AdvancementIconTemplate (VanillaTemplate , TemplateOptions ): # TODO make this inheritance work properly. Treat as single-vanilla forward or create new where needed
922+ name = "advancement"
923+ forward : Optional [str ]
924+ tints : Optional [ListOption [int | tuple [float ,float ,float ]]] # optional constant tints to apply to the item model
925+
926+ # NOTE since advancements are all in the gm4 namespace, so are these models. This template ignores the 'model' field of ModelData
927+ def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
928+ advancement_name = config .reference .split ("/" )[- 1 ]
929+ if not self .forward :
930+ item = config .item .entries ()[0 ]
931+ self .forward = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {}).get ("model" , "" ) # type: ignore ; json access is string
932+
933+ m = models_container [f"gm4:gui/advancements/{ advancement_name } " ] = Model ({
934+ "parent" : self .forward
935+ })
936+ config .model = MapOption (__root__ = {config .item .entries ()[0 ]: f"gm4:gui/advancements/{ advancement_name } " })
937+ return [m ]
938+
939+ def get_item_def_entry (self , config : ModelData , item : str ):
940+ if self .tints :
941+ return {
942+ "type" : "model" ,
943+ "model" : config .model .entries ()[0 ],
944+ "tints" : [
945+ {
946+ "type" : "minecraft:constant" ,
947+ "value" : tint
948+ }
949+ for tint in self .tints .entries ()
950+ ]
951+ }
952+ return None
953+
954+ def add_namespace (self , namespace : str ):
955+ return self .dict () | ({"forward" : add_namespace (self .forward , namespace )} if self .forward else {})
922956
923957class BlockTemplate (TemplateOptions ):
924958 name = "block"
@@ -938,7 +972,7 @@ def create_models(self, config: ModelData, models_container: NamespaceProxy[Mode
938972 }
939973 })
940974 return [m ]
941-
975+
942976class ConditionTemplate (BlankTemplate , TemplateOptions ):
943977 """Custom models using boolean condition variants (ie. broken/repaired elytra, cast/uncast fishing rods...)"""
944978 name = "condition"
@@ -964,45 +998,6 @@ def add_namespace(self, namespace: str):
964998 return self .dict () | {"on_true" : add_namespace (self .on_true , namespace ),
965999 "on_false" : add_namespace (self .on_false , namespace )}
9661000
967-
968- class AdvancementIconTemplate (TemplateOptions ):
969- name = "advancement"
970- forward : Optional [str ]
971- tints : Optional [ListOption [int | tuple [float ,float ,float ]]] # optional constant tints to apply to the item model
972- vanilla : ClassVar [Vanilla ] # mounted to by beet plugin since it requires context access
973- vanilla_jar : ClassVar [ClientJar ]
974-
975- # NOTE since advancements are all in the gm4 namespace, so are these models. This template ignores the 'model' field of ModelData
976- def create_models (self , config : ModelData , models_container : NamespaceProxy [Model ]) -> list [Model ]:
977- advancement_name = config .reference .split ("/" )[- 1 ]
978- if not self .forward :
979- item = config .item .entries ()[0 ]
980- self .forward = self .vanilla_jar .assets .item_models [add_namespace (item , "minecraft" )].data .get ("model" , {}).get ("model" , "" ) # type: ignore ; json access is string
981-
982- m = models_container [f"gm4:gui/advancements/{ advancement_name } " ] = Model ({
983- "parent" : self .forward
984- })
985- config .model = MapOption (__root__ = {config .item .entries ()[0 ]: f"gm4:gui/advancements/{ advancement_name } " })
986- return [m ]
987-
988- def get_item_def_entry (self , config : ModelData , item : str ):
989- if self .tints :
990- return {
991- "type" : "model" ,
992- "model" : config .model .entries ()[0 ],
993- "tints" : [
994- {
995- "type" : "minecraft:constant" ,
996- "value" : tint
997- }
998- for tint in self .tints .entries ()
999- ]
1000- }
1001- return None
1002-
1003- def add_namespace (self , namespace : str ):
1004- return self .dict () | ({"forward" : add_namespace (self .forward , namespace )} if self .forward else {})
1005-
10061001class ItemDisplayModel (TransformOptions ):
10071002 """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"""
10081003 origin : list [float ] = Field (..., max_items = 3 , min_items = 3 )
0 commit comments