Fix frames.

I actually broke most insertions into frames. This is much more
careful, and it now tells the player that something just can not
be put in a frame. Tested with breakable nodes, tools, and torch.

The frames autolock on things like flowers. Attempting to unlock
a frame yields a message explaining why some can not be unlocked.
This commit is contained in:
Auke Kok 2019-01-24 21:21:53 -08:00
parent 05d24a6c24
commit 9dbf15df24

View File

@ -30,17 +30,11 @@ local function frame_on_punch(pos, node, puncher, pointed_thing)
minetest.check_player_privs(puncher, "server")) then
local idef = minetest.registered_nodes[def.frame_contents]
if not idef then
return false
end
if not(idef.groups.hand or idef.groups.axe or idef.groups.shovel or idef.groups.pickaxe) then
if idef and not(idef.groups.hand or idef.groups.axe or idef.groups.shovel or idef.groups.pickaxe or idef.groups.torch) then
meta:set_int("locked", 1)
minetest.chat_send_player(name, "Item frame contains item the player can not obtain, is therefore locked")
minetest.chat_send_player(name, "Item frame contains item the player can not obtain, therefore remains locked")
return false
end
if meta:get_int("locked") == 1 then
elseif meta:get_int("locked") == 1 then
meta:set_int("locked", 0)
minetest.chat_send_player(name, "Item frame is now unlocked")
return false
@ -102,13 +96,16 @@ local function frame_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
return false
end
local idef = minetest.registered_nodes[nodename]
if not idef then
return false
local name = "frame:" .. nodename:gsub(":", "_")
local def = minetest.registered_nodes[name]
if not def then
minetest.chat_send_player(clicker:get_player_name(), "This item can not be inserted in a frame.")
return itemstack
end
local meta = minetest.get_meta(pos)
if not(idef.groups.hand or idef.groups.axe or idef.groups.shovel or idef.groups.pickaxe) then
local idef = minetest.registered_nodes[nodename]
if idef and not(idef.groups.hand or idef.groups.axe or idef.groups.shovel or idef.groups.pickaxe or idef.groups.torch) then
meta:set_int("locked", 1)
minetest.chat_send_player(clicker:get_player_name(), "Item inserted into frame is not obtainable, frame locked")
end
@ -122,12 +119,6 @@ local function frame_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
meta:set_string("metadata", metadata)
end
local name = "frame:" .. nodename:gsub(":", "_")
local def = minetest.registered_nodes[name]
if not def then
return itemstack
end
--minetest.sound_play(def.sounds.place, {pos = pos})
minetest.swap_node(pos, {name = name, param2 = node.param2})
if not minetest.setting_getbool("creative_mode") then