From 835feb35b5b70e80003dd3235797140c1b232997 Mon Sep 17 00:00:00 2001 From: Legends11 <235496468+tickwarden@users.noreply.github.com> Date: Thu, 20 Aug 2026 08:28:20 +0000 Subject: [PATCH] . --- .../crafting_ui/check_ingredients.mcfunction | 20 +++++++++---------- .../check_one_ingredient.mcfunction | 7 ++++++- .../function/debug/example_recipes.mcfunction | 1 + .../experimental/crafting_ui/craft.mcfunction | 11 ++++------ .../crafting_ui/recipes.mcfunction | 2 +- .../experimental/crafting_ui/show.mcfunction | 14 ++----------- .../tags/function/cui/load_recipes.json | 5 +++++ 7 files changed, 29 insertions(+), 31 deletions(-) create mode 100644 packs/macroEngine-Datapack-1.21.2/data/macroengine/function/debug/example_recipes.mcfunction create mode 100644 packs/macroEngine-Datapack-1.21.2/data/macroengine/tags/function/cui/load_recipes.json diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_ingredients.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_ingredients.mcfunction index b920dcd..a8f4c44 100644 --- a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_ingredients.mcfunction +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_ingredients.mcfunction @@ -1,17 +1,17 @@ # macroengine:core/internal/experimental/crafting_ui/check_ingredients [MACRO] -# Called `with storage macroengine:engine _crafting_ui.active` — receives -# the recipe compound (ingredients, result) as macro context. Recursively -# checks each ingredient is present in sufficient count via -# `clear @s 0` (count-only, does not remove — see -# player/inv/count_item.mcfunction for the same trick used elsewhere). -# Sets _crafting_ui.ok to 0b on the first missing ingredient found. +# Called `with storage macroengine:engine _crafting_ui.active`. +# Walks a COPY of ingredients (`_cui_check`) so active.ingredients +# stays intact for consume_ingredients afterwards. -execute unless data storage macroengine:engine _crafting_ui.active.ingredients[0] run return 0 +execute unless data storage macroengine:engine _cui_check run data modify storage macroengine:engine _cui_check set from storage macroengine:engine _crafting_ui.active.ingredients -data modify storage macroengine:engine _cui_ing set from storage macroengine:engine _crafting_ui.active.ingredients[0] -data remove storage macroengine:engine _crafting_ui.active.ingredients[0] +execute unless data storage macroengine:engine _cui_check[0] run return 0 + +data modify storage macroengine:engine _cui_ing set from storage macroengine:engine _cui_check[0] +data remove storage macroengine:engine _cui_check[0] function macroengine:core/internal/experimental/crafting_ui/check_one_ingredient with storage macroengine:engine _cui_ing data remove storage macroengine:engine _cui_ing -execute if data storage macroengine:engine _crafting_ui.active.ingredients[0] run function macroengine:core/internal/experimental/crafting_ui/check_ingredients with storage macroengine:engine _crafting_ui.active +# Continue only while list remains AND we have not already failed. +execute if data storage macroengine:engine _crafting_ui{ok:1b} if data storage macroengine:engine _cui_check[0] run function macroengine:core/internal/experimental/crafting_ui/check_ingredients with storage macroengine:engine _crafting_ui.active diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_one_ingredient.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_one_ingredient.mcfunction index d8ad90d..eecb2cd 100644 --- a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_one_ingredient.mcfunction +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/core/internal/experimental/crafting_ui/check_one_ingredient.mcfunction @@ -4,5 +4,10 @@ # how many the caller holds, same trick as player/inv/count_item.mcfunction. scoreboard players set $cui_have macroengine.tmp 0 -$execute store result score $cui_have macroengine.tmp run clear @s $(item) 1 +$execute store result score $cui_have macroengine.tmp run clear @s $(item) 0 + +# Fail if held count is below required. $execute unless score $cui_have macroengine.tmp matches $(count).. run data modify storage macroengine:engine _crafting_ui.ok set value 0b + +# Always report the probe so the player can see why a craft failed. +$tellraw @s ["",{"text":"[MACROENGINE] ","color":"#00AAAA","bold":true},{"text":"check ","color":"gray"},{"text":"$(item)","color":"aqua"},{"text":" have=","color":"gray"},{"score":{"name":"$cui_have","objective":"macroengine.tmp"},"color":"yellow"},{"text":" need=","color":"gray"},{"text":"$(count)","color":"yellow"}] diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/debug/example_recipes.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/debug/example_recipes.mcfunction new file mode 100644 index 0000000..9d21440 --- /dev/null +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/debug/example_recipes.mcfunction @@ -0,0 +1 @@ +data modify storage macroengine:engine _crafting_ui.recipes.example set value {ingredients:[{item:"minecraft:iron_ingot",count:2},{item:"minecraft:stick",count:1}],result:{item:"minecraft:shears",count:1}} \ No newline at end of file diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/craft.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/craft.mcfunction index 76fb62e..8966344 100644 --- a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/craft.mcfunction +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/craft.mcfunction @@ -1,10 +1,4 @@ # macroengine:experimental/crafting_ui/craft [MACRO] -# Attempts to craft the given recipe id. Looks up the recipe definition -# from experimental/crafting_ui/recipes.mcfunction (storage-based table), -# checks the caller has every required ingredient in sufficient count, -# clears them, and gives the result. All-or-nothing — nothing is -# consumed if any ingredient is missing. -# # Usage: function macroengine:experimental/crafting_ui/craft {recipe:"example"} # Caller: any player @@ -17,9 +11,12 @@ $execute unless data storage macroengine:engine _crafting_ui.recipes.$(recipe) r $data modify storage macroengine:engine _crafting_ui.active set from storage macroengine:engine _crafting_ui.recipes.$(recipe) -# Check every ingredient is present in sufficient count (all-or-nothing). +# Check every ingredient (all-or-nothing). Uses a working copy so the +# real ingredients list is still available for consume below. data modify storage macroengine:engine _crafting_ui.ok set value 1b +data remove storage macroengine:engine _cui_check function macroengine:core/internal/experimental/crafting_ui/check_ingredients with storage macroengine:engine _crafting_ui.active +data remove storage macroengine:engine _cui_check execute unless data storage macroengine:engine _crafting_ui{ok:1b} run tellraw @s ["",{"text":"[MACROENGINE] ","color":"#00AAAA","bold":true},{"text":"missing ingredients.","color":"red"}] execute unless data storage macroengine:engine _crafting_ui{ok:1b} run data remove storage macroengine:engine _crafting_ui diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/recipes.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/recipes.mcfunction index b33aa19..bfc9e87 100644 --- a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/recipes.mcfunction +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/recipes.mcfunction @@ -11,4 +11,4 @@ execute unless data storage macroengine:engine _crafting_ui run data modify storage macroengine:engine _crafting_ui set value {} data modify storage macroengine:engine _crafting_ui.recipes set value {} -data modify storage macroengine:engine _crafting_ui.recipes.example set value {ingredients:[{item:"minecraft:iron_ingot",count:2},{item:"minecraft:stick",count:1}],result:{item:"minecraft:shears",count:1}} +function #macroengine:cui/load_recipes \ No newline at end of file diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/show.mcfunction b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/show.mcfunction index 14f2238..4b098ff 100644 --- a/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/show.mcfunction +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/function/experimental/crafting_ui/show.mcfunction @@ -1,15 +1,5 @@ # macroengine:experimental/crafting_ui/show -# Prints a clickable "custom crafting" shortcut menu — each button gives -# the result item if the caller has the listed ingredients, consuming -# them. This is NOT a real crafting-table GUI (data packs can't add -# custom recipe UIs to the survival crafting grid) — it's a chat-menu -# shortcut for datapack-defined recipes that don't fit the vanilla -# 3x3 grid. Gated behind flags.experimental.crafting_ui. -# -# BACKPORT NOTE (1.21.2): same constraint as setup/open_screen.mcfunction — -# no `dialog show` / custom container screen available without a resource -# pack GUI + click-handling entity, out of scope for a first experimental -# pass. Chat-menu clickables instead. +# Prints a clickable "custom crafting" shortcut menu. # # Usage: function macroengine:experimental/crafting_ui/show # Caller: any player @@ -19,5 +9,5 @@ execute unless data storage macroengine:engine flags.experimental{crafting_ui:1b tellraw @s ["",{"text":"═══════ ","color":"dark_gray"},{"text":"macroEngine — Custom Recipes","color":"aqua","bold":true},{"text":" ═══════","color":"dark_gray"}] tellraw @s ["",{"text":"Recipes not shown in the vanilla grid. Click to attempt a craft (consumes ingredients if you have them).","color":"gray","italic":true}] -tellraw @s ["",{"text":"[Craft] ","color":"green","bold":true,"clickEvent":{"action":"run_command","value":"/function macroengine:experimental/crafting_ui/craft {recipe:\"example\"}"},"hoverEvent":{"action":"show_text","value":"See experimental/crafting_ui/recipes.mcfunction to define real recipes"}},{"text":"example — placeholder recipe","color":"white"}] +tellraw @s ["",{"text":"[Craft] ","color":"green","bold":true,"clickEvent":{"action":"run_command","value":"/function macroengine:experimental/crafting_ui/craft {recipe:\"example\"}"},"hoverEvent":{"action":"show_text","value":"Needs: 2x iron_ingot + 1x stick → 1x shears"}},{"text":"example — 2 iron_ingot + 1 stick → shears","color":"white"}] tellraw @s ["",{"text":"═════════════════════════════════════","color":"dark_gray"}] diff --git a/packs/macroEngine-Datapack-1.21.2/data/macroengine/tags/function/cui/load_recipes.json b/packs/macroEngine-Datapack-1.21.2/data/macroengine/tags/function/cui/load_recipes.json new file mode 100644 index 0000000..642ac7a --- /dev/null +++ b/packs/macroEngine-Datapack-1.21.2/data/macroengine/tags/function/cui/load_recipes.json @@ -0,0 +1,5 @@ +{ + "values": [ + "macroengine:debug/example_recipes" + ] +}