1
0
Fork 0

Itemframes: Show item name as info text

This commit is contained in:
Wuzzy 2018-05-12 19:21:41 +02:00
parent 1a786bc64f
commit 8fd2097526
1 changed files with 16 additions and 8 deletions

View File

@ -38,7 +38,7 @@ facedir[1] = {x=1,y=0,z=0}
facedir[2] = {x=0,y=0,z=-1} facedir[2] = {x=0,y=0,z=-1}
facedir[3] = {x=-1,y=0,z=0} facedir[3] = {x=-1,y=0,z=0}
local remove_item = function(pos, node) local remove_item_entity = function(pos, node)
local objs = nil local objs = nil
if node.name == "mcl_itemframes:item_frame" then if node.name == "mcl_itemframes:item_frame" then
objs = minetest.get_objects_inside_radius(pos, .5) objs = minetest.get_objects_inside_radius(pos, .5)
@ -52,8 +52,8 @@ local remove_item = function(pos, node)
end end
end end
local update_item = function(pos, node) local update_item_entity = function(pos, node)
remove_item(pos, node) remove_item_entity(pos, node)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if meta:get_string("item") ~= "" then if meta:get_string("item") ~= "" then
if node.name == "mcl_itemframes:item_frame" then if node.name == "mcl_itemframes:item_frame" then
@ -80,10 +80,11 @@ local drop_item = function(pos, node, meta)
local item = ItemStack(minetest.deserialize(meta:get_string("itemdata"))) local item = ItemStack(minetest.deserialize(meta:get_string("itemdata")))
minetest.add_item(pos, item) minetest.add_item(pos, item)
end end
meta:set_string("item","") meta:set_string("item", "")
meta:set_string("itemdata","") meta:set_string("itemdata", "")
meta:set_string("infotext", "")
end end
remove_item(pos, node) remove_item_entity(pos, node)
end end
local on_rotate local on_rotate
@ -118,8 +119,15 @@ minetest.register_node("mcl_itemframes:item_frame",{
put_itemstack:set_count(1) put_itemstack:set_count(1)
local itemdata = minetest.serialize(put_itemstack:to_table()) local itemdata = minetest.serialize(put_itemstack:to_table())
-- itemdata holds the serialized itemstack in table form -- itemdata holds the serialized itemstack in table form
update_item_entity(pos,node)
-- Add node infotext when item has been named
meta:set_string("itemdata", itemdata) meta:set_string("itemdata", itemdata)
update_item(pos,node) local imeta = itemstack:get_meta()
local iname = imeta:get_string("name")
if iname then
meta:set_string("infotext", iname)
end
if not minetest.settings:get_bool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
@ -150,6 +158,6 @@ minetest.register_lbm({
-- Swap legacy node, then respawn entity -- Swap legacy node, then respawn entity
node.name = "mcl_itemframes:item_frame" node.name = "mcl_itemframes:item_frame"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
update_item(pos, node) update_item_entity(pos, node)
end, end,
}) })