2 screwdriver = screwdriver or {}
4 minetest.register_entity("xdecor:f_item", {
7 visual_size = {x=.33,y=.33},
8 collisionbox = {0, 0, 0, 0, 0, 0},
11 on_activate = function(self, staticdata)
12 if tmp.nodename ~= nil and tmp.texture ~= nil then
13 self.nodename = tmp.nodename
15 self.texture = tmp.texture
18 if staticdata ~= nil and staticdata ~= "" then
19 local data = staticdata:split(';')
20 if data and data[1] and data[2] then
21 self.nodename = data[1]
22 self.texture = data[2]
26 if self.texture ~= nil then
27 self.object:set_properties({textures={self.texture}})
30 get_staticdata = function(self)
31 if self.nodename ~= nil and self.texture ~= nil then
32 return self.nodename .. ';' .. self.texture
38 local remove_item = function(pos, node)
40 objs = minetest.get_objects_inside_radius(pos, .5)
43 for _, obj in ipairs(objs) do
44 if obj and obj:get_luaentity() and
45 obj:get_luaentity().name == "xdecor:f_item" then
53 facedir[0] = {x=0, y=0, z=1}
54 facedir[1] = {x=1, y=0, z=0}
55 facedir[2] = {x=0, y=0, z=-1}
56 facedir[3] = {x=-1, y=0, z=0}
58 local update_item = function(pos, node)
59 remove_item(pos, node)
60 local meta = minetest.get_meta(pos)
62 if meta:get_string("item") ~= "" then
63 local posad = facedir[node.param2]
68 pos.x = pos.x + posad.x*6.5/16
69 pos.y = pos.y + posad.y*6.5/16
70 pos.z = pos.z + posad.z*6.5/16
71 tmp.nodename = node.name
72 tmp.texture = ItemStack(meta:get_string("item")):get_name()
74 local e = minetest.add_entity(pos, "xdecor:f_item")
75 local yaw = math.pi*2 - node.param2 * math.pi/2
80 local drop_item = function(pos, node)
81 local meta = minetest.get_meta(pos)
82 if meta:get_string("item") ~= "" then
83 minetest.add_item(pos, meta:get_string("item"))
84 meta:set_string("item", "")
86 remove_item(pos, node)
89 xdecor.register("frame", {
90 description = "Item frame",
92 on_rotate = screwdriver.disallow,
95 fixed = {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5}
98 "xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
99 "xdecor_wood.png", "xdecor_wood.png", "xdecor_frame.png"
101 inventory_image = "xdecor_frame.png",
102 after_place_node = function(pos, placer, itemstack)
103 local meta = minetest.get_meta(pos)
104 meta:set_string("owner", placer:get_player_name())
105 meta:set_string("infotext", "Item frame (owned by "..placer:get_player_name()..")")
107 on_rightclick = function(pos, node, clicker, itemstack)
108 if not itemstack then
112 local meta = minetest.get_meta(pos)
113 if clicker:get_player_name() == meta:get_string("owner") then
115 local s = itemstack:take_item()
116 meta:set_string("item", s:to_string())
117 update_item(pos, node)
122 on_punch = function(pos, node, puncher)
123 local meta = minetest.get_meta(pos)
124 if puncher:get_player_name() == meta:get_string("owner") then
128 can_dig = function(pos, player)
129 local meta = minetest.get_meta(pos)
130 return player:get_player_name() == meta:get_string("owner")
132 after_destruct = remove_item
135 minetest.register_abm({
136 nodenames = {"xdecor:frame"},
139 action = function(pos, node, active_object_count, active_object_count_wider)
140 if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then
143 update_item(pos, node)