Item Frame : convert update item ABM to nodetimer
This commit is contained in:
parent
619c0238ac
commit
727da4cf65
@ -34,6 +34,9 @@ local function update_item(pos, node)
|
|||||||
local entity = minetest.add_entity(pos, "xdecor:f_item")
|
local entity = minetest.add_entity(pos, "xdecor:f_item")
|
||||||
local yaw = math.pi*2 - node.param2 * math.pi/2
|
local yaw = math.pi*2 - node.param2 * math.pi/2
|
||||||
entity:setyaw(yaw)
|
entity:setyaw(yaw)
|
||||||
|
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
timer:start(15.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function drop_item(pos, node)
|
local function drop_item(pos, node)
|
||||||
@ -44,6 +47,9 @@ local function drop_item(pos, node)
|
|||||||
minetest.add_item(pos, item)
|
minetest.add_item(pos, item)
|
||||||
meta:set_string("item", "")
|
meta:set_string("item", "")
|
||||||
remove_item(pos, node)
|
remove_item(pos, node)
|
||||||
|
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
timer:stop()
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("xdecor:f_item", {
|
minetest.register_entity("xdecor:f_item", {
|
||||||
@ -94,6 +100,16 @@ xdecor.register("frame", {
|
|||||||
meta:set_string("owner", name)
|
meta:set_string("owner", name)
|
||||||
meta:set_string("infotext", "Item Frame (owned by "..name..")")
|
meta:set_string("infotext", "Item Frame (owned by "..name..")")
|
||||||
end,
|
end,
|
||||||
|
on_timer = function(pos)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
|
|
||||||
|
if num == 0 and meta:get_string("item") ~= "" then
|
||||||
|
update_item(pos, node)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end,
|
||||||
on_rightclick = function(pos, node, clicker, itemstack)
|
on_rightclick = function(pos, node, clicker, itemstack)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local player = clicker:get_player_name()
|
local player = clicker:get_player_name()
|
||||||
@ -101,7 +117,7 @@ xdecor.register("frame", {
|
|||||||
if player ~= owner or not itemstack then return end
|
if player ~= owner or not itemstack then return end
|
||||||
|
|
||||||
drop_item(pos, node)
|
drop_item(pos, node)
|
||||||
local itemstring = itemstack:take_item():to_string()
|
local itemstring = itemstack:take_item():get_name()
|
||||||
meta:set_string("item", itemstring)
|
meta:set_string("item", itemstring)
|
||||||
update_item(pos, node)
|
update_item(pos, node)
|
||||||
|
|
||||||
@ -125,12 +141,3 @@ xdecor.register("frame", {
|
|||||||
after_destruct = remove_item
|
after_destruct = remove_item
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"xdecor:frame"},
|
|
||||||
interval = 15, chance = 1,
|
|
||||||
action = function(pos, node)
|
|
||||||
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
|
||||||
if num > 0 then return end
|
|
||||||
update_item(pos, node)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
Loading…
Reference in New Issue
Block a user