show in edit options menu when a craft receipe effect fails due to changed receipe

This commit is contained in:
Sokomine 2021-06-11 00:35:11 +02:00
parent d3d90134ee
commit 28ffd87362

View File

@ -57,9 +57,7 @@ local check_block = {
"- please select -", -- 1
"If there is air: Place a block so that it looks like now.", -- 2
"If there is a block: Dig it.", -- 3
-- TODO: not sure if punching a block (as an npc) is possible without bugs
"Punch the block.", -- 4
-- TODO: not sure if right-clicking a block (as an npc) is possible without bugs
"Right-click the block.", -- 5
}
@ -140,11 +138,32 @@ yl_speak_up.show_effect = function(r)
minetest.pos_to_string(r.r_pos)..": \""..tostring(r.r_value).."\"?"
end
elseif(r.r_type == "craft") then
-- this is only shown in the edit options menu and when editing an effect;
-- we can afford a bit of calculation here (it's not a precondtion...)
if(not(r.r_value) or not(r.r_craft_grid)) then
return "ERROR: Crafting not configured correctly."
end
-- TODO: check here if the craft receipe is broken?
return "Craft \""..tostring(r.r_value).."\" from "..table.concat(r.r_craft_grid, ", ").."."
local craft_str = "Craft \""..tostring(r.r_value).."\" from "..
table.concat(r.r_craft_grid, ", ").."."
-- check here if the craft receipe is broken
local input = {}
input.items = {}
for i, v in ipairs(r.r_craft_grid) do
input.items[ i ] = ItemStack(v or "")
end
input.method = "normal" -- normal crafting; no cooking or fuel or the like
input.width = 3
local output, decremented_input = minetest.get_craft_result(input)
if(output.item:is_empty()) then
return "Error: Recipe changed! No output for "..craft_str
end
-- the craft receipe may have changed in the meantime and yield a diffrent result
local expected_stack = ItemStack(r.r_value)
if(output.item:get_name() ~= expected_stack:get_name()
or output.item:get_count() ~= expected_stack:get_count()) then
return "Error: Amount of output changed! "..craft_str
end
return craft_str
elseif(r.r_type == "on_failure") then
return "If the action (i.e. trade) failed, go to dialog \""..tostring(r.r_value).. "\"."
elseif(r.r_type == "chat_all") then
@ -155,7 +174,8 @@ yl_speak_up.show_effect = function(r)
end
-- called by yl_speak_up.input_talk(..); -- TODO
-- called by yl_speak_up.input_talk(..)
--
-- This function is called *after* the player has clicked on an option
-- and *after* any actions (i.e. trade) have been completed either
-- successfully (=action_was_succesful is true) or not.
@ -216,7 +236,7 @@ end
-- executes an effect/result r for the player and npc n_id;
-- returns true on success (relevant for on_failure)
-- TODO: in edit mode, nothing gets executed except perhaps dialog
-- Note: In edit mode, this function does not get called.
yl_speak_up.execute_effect = function(player, n_id, o_id, r)
if(not(r.r_type) or r.r_type == "") then
-- nothing to do
@ -342,6 +362,8 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
-- "a block somewhere" -- 3
elseif(r.r_type == "block") then
-- TODO: implement effect "block"
-- TODO: not sure if punching a block (as an npc) is possible without bugs
-- TODO: not sure if right-clicking a block (as an npc) is possible without bugs
-- ""NPC crafts soemthing", -- 4
elseif(r.r_type == "craft") then
if(not(r.r_craft_grid) or not(r.r_value)) then