Skip to content

Commit

Permalink
fix: merge policies were not taken into account anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Feb 28, 2024
1 parent b04fb3a commit c67401e
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 7 deletions.
5 changes: 4 additions & 1 deletion examples/basic_nested_resources/beet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require:
- beet.contrib.model_merging
- mecha.contrib.nesting
- mecha.contrib.nested_resources
resource_pack:
load: "src"
data_pack:
load: [src]
load: "src"
pipeline:
- mecha
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"parent": "item/generated",
"textures": {
"layer0": "item/bow"
},
"display": {
"thirdperson_righthand": {
"rotation": [-80, 260, -40],
"translation": [-1, -2, 2.5],
"scale": [0.9, 0.9, 0.9]
},
"thirdperson_lefthand": {
"rotation": [-80, -280, 40],
"translation": [-1, -2, 2.5],
"scale": [0.9, 0.9, 0.9]
},
"firstperson_righthand": {
"rotation": [0, -90, 25],
"translation": [1.13, 3.2, 1.13],
"scale": [0.68, 0.68, 0.68]
},
"firstperson_lefthand": {
"rotation": [0, 90, -25],
"translation": [1.13, 3.2, 1.13],
"scale": [0.68, 0.68, 0.68]
}
},
"overrides": [
{
"predicate": {
"pulling": 1
},
"model": "item/bow_pulling_0"
},
{
"predicate": {
"pulling": 1,
"pull": 0.65
},
"model": "item/bow_pulling_1"
},
{
"predicate": {
"pulling": 1,
"pull": 0.9
},
"model": "item/bow_pulling_2"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ vertex_shader minecraft:core/blit_screen:
texCoord = UV;
vertexColor = Color;
}

merge model minecraft:item/bow {
"overrides":[
{"predicate": {"custom_model_data": 1}, "model": "demo:item/cool_bow"},
{"predicate": {"custom_model_data": 1, "pulling": 1}, "model": "demo:item/cool_bow_pulling_0"},
{"predicate": {"custom_model_data": 1, "pulling": 1, "pull": 0.65}, "model": "demo:item/cool_bow_pulling_1"},
{"predicate": {"custom_model_data": 1, "pulling": 1, "pull": 0.9}, "model": "demo:item/cool_bow_pulling_2"}
]
}
12 changes: 10 additions & 2 deletions mecha/contrib/json_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,21 @@ def json_content(self, node: AstJsonContent):
if node.arguments and isinstance(content := node.arguments[0], AstJson):
target = self.database.current
if isinstance(target, JsonFileBase):
file_instance = type(target)(content.evaluate())
target_type = type(target)
file_instance = target_type(content.evaluate())

if isinstance(node, AstMergeJsonContent):
if not target.merge(file_instance):
compilation_unit = self.database[target]
if compilation_unit.pack and compilation_unit.resource_location:
compilation_unit.pack[target_type].merge({compilation_unit.resource_location: file_instance}) # type: ignore
elif not target.merge(file_instance):
target.data = file_instance.data

elif isinstance(node, AstAppendJsonContent):
target.append(file_instance) # type: ignore

elif isinstance(node, AstPrependJsonContent):
target.prepend(file_instance) # type: ignore

else:
target.data = file_instance.data
16 changes: 12 additions & 4 deletions mecha/contrib/nested_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def nested_resources(self, node: AstRoot):
),
resource_location=full_name,
no_index=True,
pack=(
self.generate.data
if file_type
in self.generate.data.resolve_scope_map().values()
else self.generate.assets
),
)
self.database[target] = compilation_unit
self.database.enqueue(target, self.database.step + 1)
Expand Down Expand Up @@ -301,12 +307,14 @@ def nested_resources(self, node: AstRoot):
original=self.database.current.original,
)

if command.identifier.startswith("merge:"):
self.generate(full_name, merge=file_instance)
changed = True
continue

target = self.generate(full_name, default=file_instance)
if target is not file_instance:
if command.identifier.startswith("merge:"):
if not target.merge(file_instance):
target.set_content(file_instance.get_content())
elif command.identifier.startswith("append:"):
if command.identifier.startswith("append:"):
target.append(file_instance) # type: ignore
elif command.identifier.startswith("prepend:"):
target.prepend(file_instance) # type: ignore
Expand Down
132 changes: 132 additions & 0 deletions tests/snapshots/examples__build_basic_nested_resources__0.pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,138 @@ say world

### minecraft

`@model minecraft:item/bow`

```json
{
"parent": "item/generated",
"textures": {
"layer0": "item/bow"
},
"display": {
"thirdperson_righthand": {
"rotation": [
-80,
260,
-40
],
"translation": [
-1,
-2,
2.5
],
"scale": [
0.9,
0.9,
0.9
]
},
"thirdperson_lefthand": {
"rotation": [
-80,
-280,
40
],
"translation": [
-1,
-2,
2.5
],
"scale": [
0.9,
0.9,
0.9
]
},
"firstperson_righthand": {
"rotation": [
0,
-90,
25
],
"translation": [
1.13,
3.2,
1.13
],
"scale": [
0.68,
0.68,
0.68
]
},
"firstperson_lefthand": {
"rotation": [
0,
90,
-25
],
"translation": [
1.13,
3.2,
1.13
],
"scale": [
0.68,
0.68,
0.68
]
}
},
"overrides": [
{
"predicate": {
"custom_model_data": 1
},
"model": "demo:item/cool_bow"
},
{
"predicate": {
"pulling": 1
},
"model": "item/bow_pulling_0"
},
{
"predicate": {
"custom_model_data": 1,
"pulling": 1
},
"model": "demo:item/cool_bow_pulling_0"
},
{
"predicate": {
"pulling": 1,
"pull": 0.65
},
"model": "item/bow_pulling_1"
},
{
"predicate": {
"custom_model_data": 1,
"pulling": 1,
"pull": 0.65
},
"model": "demo:item/cool_bow_pulling_1"
},
{
"predicate": {
"pulling": 1,
"pull": 0.9
},
"model": "item/bow_pulling_2"
},
{
"predicate": {
"custom_model_data": 1,
"pulling": 1,
"pull": 0.9
},
"model": "demo:item/cool_bow_pulling_2"
}
]
}
```

`@glsl_shader minecraft:include/matrix`

```glsl
Expand Down

0 comments on commit c67401e

Please sign in to comment.