only blocks where the player (npc owner) can build are suitable for preconditions and effects

This commit is contained in:
Sokomine 2021-06-09 22:04:07 +02:00
parent 5c8586cc50
commit d2e5840886

View File

@ -454,29 +454,39 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
if(not(block_pos) and data and data.block_pos) then if(not(block_pos) and data and data.block_pos) then
block_pos = data.block_pos block_pos = data.block_pos
end end
local error_is_protected = ""
if(block_pos) then if(block_pos) then
-- store for later usage -- store for later usage
data.block_pos = block_pos data.block_pos = block_pos
local tmp_pos = {x=block_pos.x, y=block_pos.y, z=block_pos.z} local tmp_pos = {x=block_pos.x, y=block_pos.y, z=block_pos.z}
-- TODO: effects: the player has to be able to build at that position - check that
-- "I can't punch it. The block is as the block *above* the one I punched.", -- "I can't punch it. The block is as the block *above* the one I punched.",
-- (only valid for preconditions; not for effects - because the player and -- (only valid for preconditions; not for effects - because the player and
-- his NPC need to be able to build there) -- his NPC need to be able to build there)
if(data.block and id_prefix == "p_" and data.block == 5) then if(data.block and id_prefix == "p_" and data.block == 5) then
tmp_pos.y = block_pos.y + 1 tmp_pos.y = block_pos.y + 1
end end
block_pos_str = minetest.pos_to_string(tmp_pos) -- effects (and, likewise, preconditions): the player at least has to be able to
node = minetest.get_node_or_nil(tmp_pos) -- build at that position - check that
if(not(node)) then if(minetest.is_protected(tmp_pos, pname)) then
node = {name = "- unknown -", param2 = "- unkown -"} error_is_protected = "label[0.2,7.8;Error: "..
"The position you punched is protected. It cannot be used by "..
"your NPC for checks or building. Please select a diffrent block!]"
block_pos = nil
data.block_pos = nil
else
block_pos_str = minetest.pos_to_string(tmp_pos)
node = minetest.get_node_or_nil(tmp_pos)
if(not(node)) then
node = {name = "- unknown -", param2 = "- unkown -"}
end
-- "There shall be air instead of this block.",
-- (only valid for preconditions)
if(data.block and id_prefix == "p_" and data.block == 3) then
node = {name = "air", param2 = 0}
end
-- cache that (in case a sapling grows or someone else changes it)
data.node_data = node
end end
-- "There shall be air instead of this block.",
-- (only valid for preconditions)
if(data.block and id_prefix == "p_" and data.block == 3) then
node = {name = "air", param2 = 0}
end
-- cache that (in case a sapling grows or someone else changes it)
data.node_data = node
end end
if(node.name == "- unknown -") then if(node.name == "- unknown -") then
save_button = "" save_button = ""
@ -501,7 +511,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"tooltip[select_block_pos;Click on this button to select a block.\n".. "tooltip[select_block_pos;Click on this button to select a block.\n"..
"This menu will close and you will be asked to punch\n".. "This menu will close and you will be asked to punch\n"..
"the block at the position you want to check or change.\n".. "the block at the position you want to check or change.\n"..
"After punching it, you will be returned to this menu.]" "After punching it, you will be returned to this menu.]"..
error_is_protected
-- "a trade", -- 4 -- "a trade", -- 4
-- (trade - only for preconditions; effects have something else here) -- (trade - only for preconditions; effects have something else here)