2 screwdriver = screwdriver or {}
4 minetest.register_entity("xdecor:f_item", {
5 hp_max = 1, visual="wielditem", visual_size={x=.33,y=.33},
6 collisionbox = {0, 0, 0, 0, 0, 0}, physical=false, textures={"air"},
7 on_activate = function(self, staticdata)
8 if tmp.nodename ~= nil and tmp.texture ~= nil then
9 self.nodename = tmp.nodename
11 self.texture = tmp.texture
14 if staticdata ~= nil and staticdata ~= "" then
15 local data = staticdata:split(';')
16 if data and data[1] and data[2] then
17 self.nodename = data[1]
18 self.texture = data[2]
22 if self.texture ~= nil then
23 self.object:set_properties({textures={self.texture}})
26 get_staticdata = function(self)
27 if self.nodename ~= nil and self.texture ~= nil then
28 return self.nodename .. ';' .. self.texture
34 local remove_item = function(pos, node)
36 objs = minetest.get_objects_inside_radius(pos, .5)
38 for _, obj in ipairs(objs) do
39 if obj and obj:get_luaentity() and obj:get_luaentity().name == "xdecor:f_item" then
47 facedir[0] = {x=0, y=0, z=1}
48 facedir[1] = {x=1, y=0, z=0}
49 facedir[2] = {x=0, y=0, z=-1}
50 facedir[3] = {x=-1, y=0, z=0}
52 local update_item = function(pos, node)
53 remove_item(pos, node)
54 local meta = minetest.get_meta(pos)
55 if meta:get_string("item") ~= "" then
56 local posad = facedir[node.param2]
57 if not posad then return end
58 pos.x = pos.x + posad.x*6.5/16
59 pos.y = pos.y + posad.y*6.5/16
60 pos.z = pos.z + posad.z*6.5/16
61 tmp.nodename = node.name
62 tmp.texture = ItemStack(meta:get_string("item")):get_name()
63 local e = minetest.add_entity(pos, "xdecor:f_item")
64 local yaw = math.pi*2 - node.param2 * math.pi/2
69 local drop_item = function(pos, node)
70 local meta = minetest.get_meta(pos)
71 if meta:get_string("item") ~= "" then
72 minetest.add_item(pos, meta:get_string("item"))
73 meta:set_string("item", "")
75 remove_item(pos, node)
78 xdecor.register("frame", {
79 description = "Item frame", groups = {snappy=3}, on_rotate = screwdriver.disallow,
80 node_box = { type = "fixed", fixed = {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5} },
81 tiles = {"xdecor_wood_tile.png", "xdecor_wood_tile.png", "xdecor_wood_tile.png",
82 "xdecor_wood_tile.png", "xdecor_wood_tile.png", "xdecor_frame.png"},
83 inventory_image = "xdecor_frame.png",
84 after_place_node = function(pos, placer, itemstack)
85 local meta = minetest.get_meta(pos)
86 meta:set_string("owner", placer:get_player_name())
87 meta:set_string("infotext", "Item frame (owned by "..placer:get_player_name()..")")
89 on_rightclick = function(pos, node, clicker, itemstack)
90 if not itemstack then return end
91 local meta = minetest.get_meta(pos)
92 if clicker:get_player_name() == meta:get_string("owner") then
94 local s = itemstack:take_item()
95 meta:set_string("item", s:to_string())
96 update_item(pos, node)
100 on_punch = function(pos, node, puncher)
101 local meta = minetest.get_meta(pos)
102 if puncher:get_player_name() == meta:get_string("owner") then
106 can_dig = function(pos, player)
107 local meta = minetest.get_meta(pos)
108 return player:get_player_name() == meta:get_string("owner")
110 after_destruct = remove_item
113 minetest.register_abm({
114 nodenames = {"xdecor:frame"}, interval = 15, chance = 1,
115 action = function(pos, node, active_object_count, active_object_count_wider)
116 if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then return end
117 update_item(pos, node)