Skip to content

Commit a4437fa

Browse files
[Incomplete] Move item-def handling to Templates
1 parent 03d6562 commit a4437fa

File tree

6 files changed

+129
-127
lines changed

6 files changed

+129
-127
lines changed

gm4/plugins/resource_pack.py

Lines changed: 99 additions & 99 deletions
Large diffs are not rendered by default.

gm4_end_fishing/beet.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ meta:
3131
reference: item/enderpuff
3232
- item: elytra
3333
reference: item/captains_wings
34-
model:
35-
type: condition_broken
36-
unbroken: item/elytra/captains_wings
37-
broken: item/elytra/broken_captains_wings
34+
template:
35+
name: condition
36+
property: minecraft:broken
37+
on_true: item/elytra/broken_captains_wings
38+
on_false: item/elytra/captains_wings
3839
- item: elytra
3940
reference: item/ravaged_wings
40-
model:
41-
type: condition_broken
42-
unbroken: item/elytra/ravaged_wings
43-
broken: item/elytra/broken_ravaged_wings
41+
template:
42+
name: condition
43+
property: minecraft:broken
44+
on_true: item/elytra/broken_ravaged_wings
45+
on_false: item/elytra/ravaged_wings
4446
- item: fishing_rod
4547
reference: gui/advancement/end_fishing
4648
template: advancement

gm4_metallurgy/shamir_model_template.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from beet import Context, Model, NamespaceProxy, ListOption, ResourcePack
22
from beet.contrib.vanilla import Vanilla, ClientJar
33
from beet.contrib.optifine import OptifineProperties
4-
from typing import Any, ClassVar, Literal, Optional
4+
from typing import Any, ClassVar, Literal
55
from itertools import product, chain, count
66
import re
77
import logging
88
from copy import deepcopy
99

10-
from gm4.plugins.resource_pack import ModelData, TemplateOptions, ItemModelOptions
10+
from gm4.plugins.resource_pack import ModelData, TemplateOptions, JsonType
1111
from gm4.utils import add_namespace, MapOption
1212

1313
parent_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-
232230
def 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

gm4_orb_of_ankou/pneuma_model_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PneumaTemplate(TemplateOptions):
99
"""model template to generate the models for shards and essences"""
1010
name = "pneuma"
1111

12-
def process(self, config: ModelData, models_container: NamespaceProxy[Model]):
12+
def create_models(self, config: ModelData, models_container: NamespaceProxy[Model]):
1313
pneuma = config.reference.split("/")[-1] # eg agile, anchoring ect...
1414
shard = models_container[f"gm4_orb_of_ankou:item/shards/{pneuma}"] = Model({
1515
"parent": "item/generated",

gm4_smelteries/ore_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class OreDisplayTemplate(TemplateOptions):
1414
)
1515
]
1616

17-
def process(self, config: ModelData, models_container: NamespaceProxy[Model]):
17+
def create_models(self, config: ModelData, models_container: NamespaceProxy[Model]):
1818
model_name = ensure_single_model_config(self.name, config)
1919
reference = config.reference.split('/')[-1]
2020
m = models_container[model_name] = Model({

gm4_zauber_cauldrons/assets/model_data.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ model_data:
6666
forward: item/bottled_magicol/temperate_potion
6767
- item: clock
6868
reference: gui/advancement/zauber_cauldrons_make_magicol
69-
template: advancement
69+
template:
70+
name: advancement
71+
forward: minecraft:clock_00
7072
- item: grass_block
7173
reference: gui/advancement/zauber_cauldrons_paint_biome
7274
template: advancement

0 commit comments

Comments
 (0)