1 minetest
.register_entity("mcl_itemframes:item",{
4 visual_size
= {x
=0.3,y
=0.3},
5 collisionbox
= {0,0,0,0,0,0},
7 textures
= { "empty.png" },
8 on_activate
= function(self
, staticdata
)
9 if staticdata
~= nil and staticdata
~= "" then
10 local data
= staticdata
:split(';')
11 if data
and data
[1] and data
[2] then
12 self
._nodename
= data
[1]
13 self
._texture
= data
[2]
16 if self
._texture
~= nil then
17 self
.object
:set_properties({textures
={self
._texture
}})
20 get_staticdata
= function(self
)
21 if self
._nodename
~= nil and self
._texture
~= nil then
22 return self
._nodename
.. ';' .. self
._texture
27 _update_texture
= function(self
)
28 if self
._texture
~= nil then
29 self
.object
:set_properties({textures
={self
._texture
}})
36 facedir
[0] = {x
=0,y
=0,z
=1}
37 facedir
[1] = {x
=1,y
=0,z
=0}
38 facedir
[2] = {x
=0,y
=0,z
=-1}
39 facedir
[3] = {x
=-1,y
=0,z
=0}
41 local remove_item_entity
= function(pos
, node
)
43 if node
.name
== "mcl_itemframes:item_frame" then
44 objs
= minetest
.get_objects_inside_radius(pos
, .5)
47 for _
, obj
in ipairs(objs
) do
48 if obj
and obj
:get_luaentity() and obj
:get_luaentity().name
== "mcl_itemframes:item" then
55 local update_item_entity
= function(pos
, node
)
56 remove_item_entity(pos
, node
)
57 local meta
= minetest
.get_meta(pos
)
58 if meta
:get_string("item") ~= "" then
59 if node
.name
== "mcl_itemframes:item_frame" then
60 local posad
= facedir
[node
.param2
]
61 pos
.x
= pos
.x
+ posad
.x
*6.5/16
62 pos
.y
= pos
.y
+ posad
.y
*6.5/16
63 pos
.z
= pos
.z
+ posad
.z
*6.5/16
65 local e
= minetest
.add_entity(pos
,"mcl_itemframes:item")
66 local lua
= e
:get_luaentity()
67 lua
._nodename
= node
.name
68 lua
._texture
= ItemStack(meta
:get_string("item")):get_name()
70 if node
.name
== "mcl_itemframes:item_frame" then
71 local yaw
= math
.pi
*2 - node
.param2
* math
.pi
/2
77 local drop_item
= function(pos
, node
, meta
)
78 if meta
:get_string("item") ~= "" then
79 if node
.name
== "mcl_itemframes:item_frame" and not minetest
.settings
:get_bool("creative_mode") then
80 local item
= ItemStack(minetest
.deserialize(meta
:get_string("itemdata")))
81 minetest
.add_item(pos
, item
)
83 meta
:set_string("item", "")
84 meta
:set_string("itemdata", "")
85 meta
:set_string("infotext", "")
87 remove_item_entity(pos
, node
)
91 if minetest
.get_modpath("screwdriver") then
92 on_rotate
= screwdriver
.disallow
95 minetest
.register_node("mcl_itemframes:item_frame",{
96 description
= "Item Frame",
97 _doc_items_longdesc
= "Item frames are decorative blocks in which items can be placed.",
98 _doc_items_usagehelp
= "Hold any item in your hand and right-click the item frame to place the item into the frame. Rightclick the item frame again to retrieve the item.",
100 is_ground_content
= false,
101 mesh
= "mcl_itemframes_itemframe1facedir.obj",
102 selection_box
= { type = "fixed", fixed
= {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
103 collision_box
= { type = "fixed", fixed
= {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
104 tiles
= {"mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "mcl_itemframes_itemframe_background.png", "default_wood.png", "mcl_itemframes_itemframe_background.png"},
105 inventory_image
= "mcl_itemframes_item_frame.png",
106 wield_image
= "mcl_itemframes_item_frame.png",
108 paramtype2
= "facedir",
109 sunlight_propagates
= true,
110 groups
= { dig_immediate
=3,deco_block
=1,dig_by_piston
=1},
111 sounds
= mcl_sounds
.node_sound_defaults(),
112 on_rightclick
= function(pos
, node
, clicker
, itemstack
)
113 if not itemstack
then return end
114 local meta
= minetest
.get_meta(pos
)
115 drop_item(pos
, node
, meta
)
116 -- item holds the itemstring
117 meta
:set_string("item", itemstack
:get_name())
118 local put_itemstack
= ItemStack(itemstack
)
119 put_itemstack
:set_count(1)
120 local itemdata
= minetest
.serialize(put_itemstack
:to_table())
121 -- itemdata holds the serialized itemstack in table form
122 update_item_entity(pos
,node
)
123 -- Add node infotext when item has been named
124 meta
:set_string("itemdata", itemdata
)
125 local imeta
= itemstack
:get_meta()
126 local iname
= imeta
:get_string("name")
128 meta
:set_string("infotext", iname
)
131 if not minetest
.settings
:get_bool("creative_mode") then
132 itemstack
:take_item()
136 on_destruct
= function(pos
)
137 local meta
= minetest
.get_meta(pos
)
138 local node
= minetest
.get_node(pos
)
139 drop_item(pos
, node
, meta
)
141 on_rotate
= on_rotate
,
144 minetest
.register_craft({
145 output
= 'mcl_itemframes:item_frame',
147 {'mcl_core:stick', 'mcl_core:stick', 'mcl_core:stick'},
148 {'mcl_core:stick', 'mcl_mobitems:leather', 'mcl_core:stick'},
149 {'mcl_core:stick', 'mcl_core:stick', 'mcl_core:stick'},
153 minetest
.register_lbm({
154 label
= "Update legacy item frames",
155 name
= "mcl_itemframes:update_legacy_item_frames",
156 nodenames
= {"itemframes:frame"},
157 action
= function(pos
, node
)
158 -- Swap legacy node, then respawn entity
159 node
.name
= "mcl_itemframes:item_frame"
160 minetest
.swap_node(pos
, node
)
161 update_item_entity(pos
, node
)