Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom crafting recipes as official JSON recipes #1053

Merged
merged 20 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beet-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pipeline:
- gm4.plugins.output
- gm4.plugins.player_heads
- gm4.plugins.resource_pack
- gm4.plugins.attribute_rewrite
- gm4.plugins.backwards
- beet.contrib.model_merging
- beet.contrib.optifine
- beet.contrib.babelbox
Expand Down
2 changes: 1 addition & 1 deletion beet-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pipeline:
- gm4.plugins.manifest.update_patch
- gm4.plugins.player_heads
- gm4.plugins.resource_pack
- gm4.plugins.attribute_rewrite
- gm4.plugins.backwards
- beet.contrib.model_merging
- beet.contrib.optifine
- beet.contrib.babelbox
Expand Down
2 changes: 1 addition & 1 deletion beet-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pipeline:
- gm4.plugins.output.test
- gm4.plugins.player_heads
- gm4.plugins.resource_pack
- gm4.plugins.attribute_rewrite
- gm4.plugins.backwards
- gm4_guidebook.generate_guidebooks.load_page_data
- gm4_guidebook.generate_guidebooks.load_custom_recipes
- gm4.plugins.test.load_tests
Expand Down
66 changes: 62 additions & 4 deletions gm4/plugins/attribute_rewrite.py → gm4/plugins/backwards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from beet import Context, TextFileBase
import re
import logging
from typing import Any
from beet import Context, TextFileBase, Recipe

logger = logging.getLogger("gm4.backwards")

# Generates overlays to support older versions
def beet_default(ctx: Context):
yield

rewrite_attributes(ctx)
rewrite_recipes(ctx)


ATTRIBUTES_RENAMES = {
"minecraft:armor": "minecraft:generic.armor",
Expand Down Expand Up @@ -36,9 +48,8 @@
"minecraft:water_movement_efficiency": "minecraft:generic.water_movement_efficiency",
}

def beet_default(ctx: Context):
yield

# Removes the generic. and other prefixes from attribute IDs
def rewrite_attributes(ctx: Context):
for id, resource in ctx.data.all():
if isinstance(resource, TextFileBase):
resource.source_stop
Expand All @@ -51,3 +62,50 @@ def beet_default(ctx: Context):
overlay = ctx.data.overlays["overlay_48"]
overlay.supported_formats = { "min_inclusive": 48, "max_inclusive": 48 }
overlay[id] = overlay_resource


# Rewrites the recipe ingredients to the old {"item": "..."} format
def rewrite_recipes(ctx: Context):

def rewrite_ingredient(ingr: str | list[str]) -> Any:
if isinstance(ingr, list):
return [rewrite_ingredient(item) for item in ingr]
if ingr.startswith("#"):
return { "tag": ingr[1:] }
return { "item": ingr }

def rewrite_recipe(id: str, resource: Recipe):
# If an overlay already exists for this recipe, us the contents of that
# TODO: generalize this for all rewrite functions and handle multiple overlays
for overlay in ctx.data.overlays.values():
if id in overlay.recipes:
resource = overlay.recipes[id]
break

overlay_resource = resource.copy()
data = overlay_resource.data

if "crafting_transmute" in data["type"]:
logger.warning(f"Cannot backport crafting_transmute recipe {id}")
return

if "base" in data:
data["base"] = rewrite_ingredient(data["base"])
if "addition" in data:
data["addition"] = rewrite_ingredient(data["addition"])
if "ingredient" in data:
data["ingredient"] = rewrite_ingredient(data["ingredient"])
if "ingredients" in data:
data["ingredients"] = [rewrite_ingredient(ingr) for ingr in data["ingredients"]]
if "key" in data:
data["key"] = {k: rewrite_ingredient(ingr) for k, ingr in data["key"].items()}

overlay = ctx.data.overlays["overlay_48"]
overlay.supported_formats = { "min_inclusive": 48, "max_inclusive": 48 }
overlay[id] = overlay_resource

for id, resource in ctx.data.recipes.items():
try:
rewrite_recipe(id, resource)
except BaseException as e:
logger.error(f"Failed to backport recipe {id}: {e}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "gm4_block_compressors:compressor"
}
},
"has_materials": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": [
"minecraft:purpur_block",
"minecraft:purpur_pillar",
"minecraft:piston",
"minecraft:obsidian"
]
}
]
}
}
},
"requirements": [
[
"has_the_recipe",
"has_materials"
]
],
"rewards": {
"recipes": [
"gm4_block_compressors:compressor"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "minecraft:crafting_shaped",
"category": "redstone",
"pattern": [
"IPI",
"pOp",
"CCC"
],
"key": {
"I": "minecraft:iron_ingot",
"P": "minecraft:purpur_block",
"p": "minecraft:piston",
"O": "minecraft:obsidian",
"C": "minecraft:cobblestone"
},
"result": {
"id": "minecraft:player_head",
"components": {
"minecraft:custom_model_data": "block/block_compressor_full",
"minecraft:profile": "$block_compressor",
"minecraft:custom_data": "{gm4_machines:{id:'block_compressor'}}",
"minecraft:custom_name": "{\"translate\":\"block.gm4.block_compressor\",\"fallback\":\"Compressor\",\"color\":\"white\",\"italic\":false}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "gm4_boots_of_ostara:boots_of_ostara"
}
},
"has_materials": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": [
"minecraft:leather_boots",
"minecraft:moss_block",
"minecraft:grass_block"
]
}
]
}
}
},
"requirements": [
[
"has_the_recipe",
"has_materials"
]
],
"rewards": {
"recipes": [
"gm4_boots_of_ostara:boots_of_ostara"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"pattern": [
" S ",
"MLG",
" W "
],
"key": {
"S": "minecraft:wheat_seeds",
"M": "minecraft:moss_block",
"L": "minecraft:leather_boots",
"G": "minecraft:grass_block",
"W": "minecraft:water_bucket"
},
"result": {
"id": "minecraft:leather_boots",
"components": {
"minecraft:dyed_color": {
"rgb": 3705899,
"show_in_tooltip": false
},
"minecraft:custom_model_data": "item/boots_of_ostara",
"minecraft:custom_data": "{gm4_boots_of_ostara:1b}",
"minecraft:custom_name": "{\"translate\": \"item.gm4.boots_of_ostara\",\"fallback\": \"Boots of Ostara\",\"italic\": false}",
"minecraft:lore": [
"{\"translate\":\"item.gm4.boots_of_ostara.lore\",\"fallback\":\"Brings abundance beneath you!\",\"color\":\"dark_gray\",\"italic\":false}"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "gm4_disassemblers:disassembler"
}
},
"has_materials": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": [
"minecraft:tnt",
"minecraft:stonecutter",
"minecraft:obsidian"
]
}
]
}
}
},
"requirements": [
[
"has_the_recipe",
"has_materials"
]
],
"rewards": {
"recipes": [
"gm4_disassemblers:disassembler"
]
}
}
25 changes: 25 additions & 0 deletions gm4_disassemblers/data/gm4_disassemblers/recipe/disassembler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "minecraft:crafting_shaped",
"category": "redstone",
"pattern": [
"ITI",
"OSO",
"CCC"
],
"key": {
"I": "minecraft:iron_ingot",
"T": "minecraft:tnt",
"O": "minecraft:obsidian",
"S": "minecraft:stonecutter",
"C": "minecraft:cobblestone"
},
"result": {
"id": "minecraft:player_head",
"components": {
"minecraft:custom_model_data": "item/disassembler",
"minecraft:profile": "$disassembler",
"minecraft:custom_data": "{gm4_machines:{id:'disassembler'}}",
"minecraft:custom_name": "{\"translate\":\"block.gm4.disassembler\",\"fallback\":\"Disassembler\",\"color\":\"white\",\"italic\":false}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "gm4_enchantment_extractors:enchantment_extractor"
}
},
"has_materials": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": [
"minecraft:enchanting_table",
"minecraft:grindstone"
]
}
]
}
}
},
"requirements": [
[
"has_the_recipe",
"has_materials"
]
],
"rewards": {
"recipes": [
"gm4_enchantment_extractors:enchantment_extractor"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"category": "redstone",
"pattern": [
" E ",
"GgG",
"CCC"
],
"key": {
"E": "minecraft:enchanting_table",
"G": "minecraft:gold_ingot",
"g": "minecraft:grindstone",
"C": "minecraft:cobblestone"
},
"result": {
"id": "minecraft:player_head",
"components": {
"minecraft:custom_model_data": "item/enchantment_extractor",
"minecraft:profile": "$enchantment_extractor",
"minecraft:custom_data": "{gm4_machines:{id:'enchantment_extractor'}}",
"minecraft:custom_name": "{\"translate\":\"block.gm4.enchantment_extractor\",\"fallback\":\"Enchantment Extractor\",\"color\":\"white\",\"italic\":false}"
}
}
}
Loading
Loading