2 screwdriver
= screwdriver
or {}
6 minetest
.register_entity("itemframes:item",{
9 visual_size
={x
= 0.33, y
= 0.33},
10 collisionbox
= {0, 0, 0, 0, 0, 0},
13 on_activate
= function(self
, staticdata
)
15 if mobs
and mobs
.entity
and mobs
.entity
== false then
20 if tmp
.nodename
~= nil and tmp
.texture
~= nil then
21 self
.nodename
= tmp
.nodename
23 self
.texture
= tmp
.texture
26 if staticdata
~= nil and staticdata
~= "" then
27 local data
= staticdata
:split(';')
28 if data
and data
[1] and data
[2] then
29 self
.nodename
= data
[1]
30 self
.texture
= data
[2]
34 if self
.texture
~= nil then
35 self
.object
:set_properties({textures
= {self
.texture
}})
37 if self
.nodename
== "itemframes:pedestal" then
38 self
.object
:set_properties({automatic_rotate
= 1})
41 get_staticdata
= function(self
)
42 if self
.nodename
~= nil and self
.texture
~= nil then
43 return self
.nodename
.. ';' .. self
.texture
50 facedir
[0] = {x
= 0, y
= 0, z
= 1}
51 facedir
[1] = {x
= 1, y
= 0, z
= 0}
52 facedir
[2] = {x
= 0, y
= 0, z
= -1}
53 facedir
[3] = {x
= -1, y
= 0, z
= 0}
57 local remove_item
= function(pos
, node
)
59 if node
.name
== "itemframes:frame" then
60 objs
= minetest
.get_objects_inside_radius(pos
, 0.5)
61 elseif node
.name
== "itemframes:pedestal" then
63 objs
= minetest
.get_objects_inside_radius(pos
, 0.5)
67 for _
, obj
in ipairs(objs
) do
68 if obj
and obj
:get_luaentity()
69 and obj
:get_luaentity().name
== "itemframes:item" then
76 local update_item
= function(pos
, node
)
77 remove_item(pos
, node
)
78 local meta
= minetest
.get_meta(pos
)
79 if meta
:get_string("item") ~= "" then
80 if node
.name
== "itemframes:frame" then
81 local posad
= facedir
[node
.param2
]
82 if not posad
then return end
83 pos
.x
= pos
.x
+ posad
.x
* 6.5 / 16
84 pos
.y
= pos
.y
+ posad
.y
* 6.5 / 16
85 pos
.z
= pos
.z
+ posad
.z
* 6.5 / 16
86 elseif node
.name
== "itemframes:pedestal" then
87 pos
.y
= pos
.y
+ 12 / 16 + 0.33
89 tmp
.nodename
= node
.name
90 tmp
.texture
= ItemStack(meta
:get_string("item")):get_name()
91 local e
= minetest
.add_entity(pos
,"itemframes:item")
92 if node
.name
== "itemframes:frame" then
93 local yaw
= math
.pi
* 2 - node
.param2
* math
.pi
/ 2
99 local drop_item
= function(pos
, node
)
100 local meta
= minetest
.get_meta(pos
)
101 if meta
:get_string("item") ~= "" then
102 if node
.name
== "itemframes:frame" then
103 minetest
.add_item(pos
, meta
:get_string("item"))
104 elseif node
.name
== "itemframes:pedestal" then
106 minetest
.add_item(pos
, meta
:get_string("item"))
109 meta
:set_string("item","")
111 remove_item(pos
, node
)
116 minetest
.register_node("itemframes:frame",{
117 description
= "Item Frame",
118 drawtype
= "nodebox",
121 fixed
= {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5}
125 fixed
= {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5}
127 tiles
= {"itemframes_frame.png"},
128 inventory_image
= "itemframes_frame.png",
129 wield_image
= "itemframes_frame.png",
131 paramtype2
= "facedir",
132 sunlight_propagates
= true,
133 groups
= {choppy
= 2, dig_immediate
= 2},
134 legacy_wallmounted
= true,
135 sounds
= hades_sounds
.node_sound_defaults(),
136 on_rotate
= screwdriver
.disallow
,
138 after_place_node
= function(pos
, placer
, itemstack
)
139 local meta
= minetest
.get_meta(pos
)
140 meta
:set_string("infotext","Item frame (right-click to add/remove item)")
143 on_rightclick
= function(pos
, node
, clicker
, itemstack
)
144 if not itemstack
then return end
145 if minetest
.is_protected(pos
, clicker
:get_player_name()) then return end
146 local meta
= minetest
.get_meta(pos
)
147 if meta
:get_string("item") ~= "" then
150 local s
= itemstack
:take_item()
151 meta
:set_string("item", s
:to_string())
152 update_item(pos
,node
)
157 on_destruct
= function(pos
)
158 drop_item(pos
, minetest
.get_node(pos
))
161 on_punch
= function(pos
, node
, puncher
)
162 update_item(pos
, node
)
166 minetest
.register_node("itemframes:pedestal",{
167 description
= "Pedestal",
168 drawtype
= "nodebox",
169 node_box
= { type = "fixed", fixed
= {
170 {-7/16, -8/16, -7/16, 7/16, -7/16, 7/16}, -- bottom plate
171 {-6/16, -7/16, -6/16, 6/16, -6/16, 6/16}, -- bottom plate (upper)
172 {-0.25, -6/16, -0.25, 0.25, 11/16, 0.25}, -- pillar
173 {-7/16, 11/16, -7/16, 7/16, 12/16, 7/16}, -- top plate
177 fixed
= {-7/16, -0.5, -7/16, 7/16, 12/16, 7/16}
179 tiles
= {"itemframes_pedestal.png"},
181 groups
= {cracky
= 3},
182 sounds
= hades_sounds
.node_sound_defaults(),
183 on_rotate
= screwdriver
.disallow
,
185 after_place_node
= function(pos
, placer
, itemstack
)
186 local meta
= minetest
.get_meta(pos
)
187 meta
:set_string("infotext","Pedestal (right-click to add/remove item)")
190 on_rightclick
= function(pos
, node
, clicker
, itemstack
)
191 if not itemstack
then return end
192 if minetest
.is_protected(pos
, clicker
:get_player_name()) then return end
193 local meta
= minetest
.get_meta(pos
)
194 if meta
:get_string("item") ~= "" then
197 local s
= itemstack
:take_item()
198 meta
:set_string("item", s
:to_string())
199 update_item(pos
,node
)
204 on_destruct
= function(pos
)
205 drop_item(pos
, minetest
.get_node(pos
))
208 on_punch
= function(pos
, node
, puncher
)
209 update_item(pos
, node
)
213 -- automatically restore entities lost from frames/pedestals
214 -- due to /clearobjects or similar
216 minetest
.register_abm({
217 label
= "Respawn entities of item frames and pedestals",
218 nodenames
= {"itemframes:frame", "itemframes:pedestal"},
221 action
= function(pos
, node
, active_object_count
, active_object_count_wider
)
225 if node
.name
== "itemframes:frame" then
226 num
= #minetest
.get_objects_inside_radius(pos
, 0.5)
227 elseif node
.name
== "itemframes:pedestal" then
229 num
= #minetest
.get_objects_inside_radius(pos
, 0.5)
233 if num
> 0 then return end
234 update_item(pos
, node
)
240 minetest
.register_craft({
241 output
= 'itemframes:frame',
243 {'group:stick', 'group:stick', 'group:stick'},
244 {'group:stick', 'hades_core:paper', 'group:stick'},
245 {'group:stick', 'group:stick', 'group:stick'},
249 minetest
.register_craft({
250 output
= 'itemframes:pedestal',
252 {'hades_core:stone', 'hades_core:stone', 'hades_core:stone'},
253 {'', 'hades_core:stone', ''},
254 {'hades_core:stone', 'hades_core:stone', 'hades_core:stone'},