Skip to content

Commit 0bbbf2a

Browse files
authored
Implement custom crafting recipes as official JSON recipes (#1053)
* Port custom crafting recipes to official JSON recipes when possible Leaving out: auto crafter, heart canister tier 2, relocators, scuba gear Slightly modifiers: ender hopper minecart, liquid minecart Discarding item data: boots of ostara, mountaineering * Add recipe unlock advancements * Update record crafting advancement * Optimize scuba gear advancement * Fix red_nether_bricks unlock was missing * Add group field to forming press recipes * Add standard crafting recipes except stairs and slabs * Generate standard crafting slabs and stairs recipes * Group stairs and slabs recipes together with vanilla recipes * Revert forming press changes * Update recipes to 1.21.3 * Update standard crafting recipes * Remove attribute prefix from crampons recipe * Keep the old format for gm4_recipes * Backport recipes with beet * Handle when both attributes and recipe rewrites affect the same file * Catch recipe rewrite errors * Remove manually backported soul glass recipe
1 parent 6a170cd commit 0bbbf2a

File tree

104 files changed

+2554
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2554
-53
lines changed

beet-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pipeline:
77
- gm4.plugins.output
88
- gm4.plugins.player_heads
99
- gm4.plugins.resource_pack
10-
- gm4.plugins.attribute_rewrite
10+
- gm4.plugins.backwards
1111
- beet.contrib.model_merging
1212
- beet.contrib.optifine
1313
- beet.contrib.babelbox

beet-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pipeline:
3939
- gm4.plugins.manifest.update_patch
4040
- gm4.plugins.player_heads
4141
- gm4.plugins.resource_pack
42-
- gm4.plugins.attribute_rewrite
42+
- gm4.plugins.backwards
4343
- beet.contrib.model_merging
4444
- beet.contrib.optifine
4545
- beet.contrib.babelbox

beet-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pipeline:
99
- gm4.plugins.output.test
1010
- gm4.plugins.player_heads
1111
- gm4.plugins.resource_pack
12-
- gm4.plugins.attribute_rewrite
12+
- gm4.plugins.backwards
1313
- gm4_guidebook.generate_guidebooks.load_page_data
1414
- gm4_guidebook.generate_guidebooks.load_custom_recipes
1515
- gm4.plugins.test.load_tests
Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
from beet import Context, TextFileBase
21
import re
2+
import logging
3+
from typing import Any
4+
from beet import Context, TextFileBase, Recipe
5+
6+
logger = logging.getLogger("gm4.backwards")
7+
8+
# Generates overlays to support older versions
9+
def beet_default(ctx: Context):
10+
yield
11+
12+
rewrite_attributes(ctx)
13+
rewrite_recipes(ctx)
14+
315

416
ATTRIBUTES_RENAMES = {
517
"minecraft:armor": "minecraft:generic.armor",
@@ -36,9 +48,8 @@
3648
"minecraft:water_movement_efficiency": "minecraft:generic.water_movement_efficiency",
3749
}
3850

39-
def beet_default(ctx: Context):
40-
yield
41-
51+
# Removes the generic. and other prefixes from attribute IDs
52+
def rewrite_attributes(ctx: Context):
4253
for id, resource in ctx.data.all():
4354
if isinstance(resource, TextFileBase):
4455
resource.source_stop
@@ -51,3 +62,50 @@ def beet_default(ctx: Context):
5162
overlay = ctx.data.overlays["overlay_48"]
5263
overlay.supported_formats = { "min_inclusive": 48, "max_inclusive": 48 }
5364
overlay[id] = overlay_resource
65+
66+
67+
# Rewrites the recipe ingredients to the old {"item": "..."} format
68+
def rewrite_recipes(ctx: Context):
69+
70+
def rewrite_ingredient(ingr: str | list[str]) -> Any:
71+
if isinstance(ingr, list):
72+
return [rewrite_ingredient(item) for item in ingr]
73+
if ingr.startswith("#"):
74+
return { "tag": ingr[1:] }
75+
return { "item": ingr }
76+
77+
def rewrite_recipe(id: str, resource: Recipe):
78+
# If an overlay already exists for this recipe, us the contents of that
79+
# TODO: generalize this for all rewrite functions and handle multiple overlays
80+
for overlay in ctx.data.overlays.values():
81+
if id in overlay.recipes:
82+
resource = overlay.recipes[id]
83+
break
84+
85+
overlay_resource = resource.copy()
86+
data = overlay_resource.data
87+
88+
if "crafting_transmute" in data["type"]:
89+
logger.warning(f"Cannot backport crafting_transmute recipe {id}")
90+
return
91+
92+
if "base" in data:
93+
data["base"] = rewrite_ingredient(data["base"])
94+
if "addition" in data:
95+
data["addition"] = rewrite_ingredient(data["addition"])
96+
if "ingredient" in data:
97+
data["ingredient"] = rewrite_ingredient(data["ingredient"])
98+
if "ingredients" in data:
99+
data["ingredients"] = [rewrite_ingredient(ingr) for ingr in data["ingredients"]]
100+
if "key" in data:
101+
data["key"] = {k: rewrite_ingredient(ingr) for k, ingr in data["key"].items()}
102+
103+
overlay = ctx.data.overlays["overlay_48"]
104+
overlay.supported_formats = { "min_inclusive": 48, "max_inclusive": 48 }
105+
overlay[id] = overlay_resource
106+
107+
for id, resource in ctx.data.recipes.items():
108+
try:
109+
rewrite_recipe(id, resource)
110+
except BaseException as e:
111+
logger.error(f"Failed to backport recipe {id}: {e}")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"parent": "minecraft:recipes/root",
3+
"criteria": {
4+
"has_the_recipe": {
5+
"trigger": "minecraft:recipe_unlocked",
6+
"conditions": {
7+
"recipe": "gm4_block_compressors:compressor"
8+
}
9+
},
10+
"has_materials": {
11+
"trigger": "minecraft:inventory_changed",
12+
"conditions": {
13+
"items": [
14+
{
15+
"items": [
16+
"minecraft:purpur_block",
17+
"minecraft:purpur_pillar",
18+
"minecraft:piston",
19+
"minecraft:obsidian"
20+
]
21+
}
22+
]
23+
}
24+
}
25+
},
26+
"requirements": [
27+
[
28+
"has_the_recipe",
29+
"has_materials"
30+
]
31+
],
32+
"rewards": {
33+
"recipes": [
34+
"gm4_block_compressors:compressor"
35+
]
36+
}
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"category": "redstone",
4+
"pattern": [
5+
"IPI",
6+
"pOp",
7+
"CCC"
8+
],
9+
"key": {
10+
"I": "minecraft:iron_ingot",
11+
"P": "minecraft:purpur_block",
12+
"p": "minecraft:piston",
13+
"O": "minecraft:obsidian",
14+
"C": "minecraft:cobblestone"
15+
},
16+
"result": {
17+
"id": "minecraft:player_head",
18+
"components": {
19+
"minecraft:custom_model_data": "block/block_compressor_full",
20+
"minecraft:profile": "$block_compressor",
21+
"minecraft:custom_data": "{gm4_machines:{id:'block_compressor'}}",
22+
"minecraft:custom_name": "{\"translate\":\"block.gm4.block_compressor\",\"fallback\":\"Compressor\",\"color\":\"white\",\"italic\":false}"
23+
}
24+
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"parent": "minecraft:recipes/root",
3+
"criteria": {
4+
"has_the_recipe": {
5+
"trigger": "minecraft:recipe_unlocked",
6+
"conditions": {
7+
"recipe": "gm4_boots_of_ostara:boots_of_ostara"
8+
}
9+
},
10+
"has_materials": {
11+
"trigger": "minecraft:inventory_changed",
12+
"conditions": {
13+
"items": [
14+
{
15+
"items": [
16+
"minecraft:leather_boots",
17+
"minecraft:moss_block",
18+
"minecraft:grass_block"
19+
]
20+
}
21+
]
22+
}
23+
}
24+
},
25+
"requirements": [
26+
[
27+
"has_the_recipe",
28+
"has_materials"
29+
]
30+
],
31+
"rewards": {
32+
"recipes": [
33+
"gm4_boots_of_ostara:boots_of_ostara"
34+
]
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"category": "equipment",
4+
"pattern": [
5+
" S ",
6+
"MLG",
7+
" W "
8+
],
9+
"key": {
10+
"S": "minecraft:wheat_seeds",
11+
"M": "minecraft:moss_block",
12+
"L": "minecraft:leather_boots",
13+
"G": "minecraft:grass_block",
14+
"W": "minecraft:water_bucket"
15+
},
16+
"result": {
17+
"id": "minecraft:leather_boots",
18+
"components": {
19+
"minecraft:dyed_color": {
20+
"rgb": 3705899,
21+
"show_in_tooltip": false
22+
},
23+
"minecraft:custom_model_data": "item/boots_of_ostara",
24+
"minecraft:custom_data": "{gm4_boots_of_ostara:1b}",
25+
"minecraft:custom_name": "{\"translate\": \"item.gm4.boots_of_ostara\",\"fallback\": \"Boots of Ostara\",\"italic\": false}",
26+
"minecraft:lore": [
27+
"{\"translate\":\"item.gm4.boots_of_ostara.lore\",\"fallback\":\"Brings abundance beneath you!\",\"color\":\"dark_gray\",\"italic\":false}"
28+
]
29+
}
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"parent": "minecraft:recipes/root",
3+
"criteria": {
4+
"has_the_recipe": {
5+
"trigger": "minecraft:recipe_unlocked",
6+
"conditions": {
7+
"recipe": "gm4_disassemblers:disassembler"
8+
}
9+
},
10+
"has_materials": {
11+
"trigger": "minecraft:inventory_changed",
12+
"conditions": {
13+
"items": [
14+
{
15+
"items": [
16+
"minecraft:tnt",
17+
"minecraft:stonecutter",
18+
"minecraft:obsidian"
19+
]
20+
}
21+
]
22+
}
23+
}
24+
},
25+
"requirements": [
26+
[
27+
"has_the_recipe",
28+
"has_materials"
29+
]
30+
],
31+
"rewards": {
32+
"recipes": [
33+
"gm4_disassemblers:disassembler"
34+
]
35+
}
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"type": "minecraft:crafting_shaped",
3+
"category": "redstone",
4+
"pattern": [
5+
"ITI",
6+
"OSO",
7+
"CCC"
8+
],
9+
"key": {
10+
"I": "minecraft:iron_ingot",
11+
"T": "minecraft:tnt",
12+
"O": "minecraft:obsidian",
13+
"S": "minecraft:stonecutter",
14+
"C": "minecraft:cobblestone"
15+
},
16+
"result": {
17+
"id": "minecraft:player_head",
18+
"components": {
19+
"minecraft:custom_model_data": "item/disassembler",
20+
"minecraft:profile": "$disassembler",
21+
"minecraft:custom_data": "{gm4_machines:{id:'disassembler'}}",
22+
"minecraft:custom_name": "{\"translate\":\"block.gm4.disassembler\",\"fallback\":\"Disassembler\",\"color\":\"white\",\"italic\":false}"
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)