Skip to content
Merged

. #37

Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -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 <item> 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
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Original file line number Diff line number Diff line change
@@ -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}}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"macroengine:debug/example_recipes"
]
}
Loading