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 _texture
= "empty.png",
10 on_activate
= function(self
, staticdata
)
11 if staticdata
~= nil and staticdata
~= "" then
12 local data
= staticdata
:split(';')
13 if data
and data
[1] and data
[2] then
14 self
._nodename
= data
[1]
15 self
._texture
= data
[2]
18 if self
._texture
~= nil then
19 self
.object
:set_properties({textures
={self
._texture
}})
22 get_staticdata
= function(self
)
23 if self
._nodename
~= nil and self
._texture
~= nil then
24 return self
._nodename
.. ';' .. self
._texture
29 _update_texture
= function(self
)
30 if self
._texture
~= nil then
31 self
.object
:set_properties({textures
={self
._texture
}})
38 facedir
[0] = {x
=0,y
=0,z
=1}
39 facedir
[1] = {x
=1,y
=0,z
=0}
40 facedir
[2] = {x
=0,y
=0,z
=-1}
41 facedir
[3] = {x
=-1,y
=0,z
=0}
43 local remove_item_entity
= function(pos
, node
)
45 if node
.name
== "mcl_itemframes:item_frame" then
46 objs
= minetest
.get_objects_inside_radius(pos
, .5)
49 for _
, obj
in ipairs(objs
) do
50 if obj
and obj
:get_luaentity() and obj
:get_luaentity().name
== "mcl_itemframes:item" then
57 local update_item_entity
= function(pos
, node
)
58 remove_item_entity(pos
, node
)
59 local meta
= minetest
.get_meta(pos
)
60 local inv
= meta
:get_inventory()
61 local item
= inv
:get_stack("main", 1)
62 if not item
:is_empty() then
63 if node
.name
== "mcl_itemframes:item_frame" then
64 local posad
= facedir
[node
.param2
]
65 pos
.x
= pos
.x
+ posad
.x
*6.5/16
66 pos
.y
= pos
.y
+ posad
.y
*6.5/16
67 pos
.z
= pos
.z
+ posad
.z
*6.5/16
69 local e
= minetest
.add_entity(pos
, "mcl_itemframes:item")
70 local lua
= e
:get_luaentity()
71 lua
._nodename
= node
.name
72 if item
:get_name() == "" then
73 lua
._texture
= "blank.png"
75 lua
._texture
= item
:get_name()
78 if node
.name
== "mcl_itemframes:item_frame" then
79 local yaw
= math
.pi
*2 - node
.param2
* math
.pi
/2
85 local drop_item
= function(pos
, node
, meta
)
86 if node
.name
== "mcl_itemframes:item_frame" and not minetest
.settings
:get_bool("creative_mode") then
87 local inv
= meta
:get_inventory()
88 local item
= inv
:get_stack("main", 1)
89 if not item
:is_empty() then
90 minetest
.add_item(pos
, item
)
93 meta
:set_string("infotext", "")
94 remove_item_entity(pos
, node
)
98 if minetest
.get_modpath("screwdriver") then
99 on_rotate
= screwdriver
.disallow
102 minetest
.register_node("mcl_itemframes:item_frame",{
103 description
= "Item Frame",
104 _doc_items_longdesc
= "Item frames are decorative blocks in which items can be placed.",
105 _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.",
107 is_ground_content
= false,
108 mesh
= "mcl_itemframes_itemframe1facedir.obj",
109 selection_box
= { type = "fixed", fixed
= {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
110 collision_box
= { type = "fixed", fixed
= {-6/16, -6/16, 7/16, 6/16, 6/16, 0.5} },
111 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"},
112 inventory_image
= "mcl_itemframes_item_frame.png",
113 wield_image
= "mcl_itemframes_item_frame.png",
115 paramtype2
= "facedir",
116 sunlight_propagates
= true,
117 groups
= { dig_immediate
=3,deco_block
=1,dig_by_piston
=1,container
=7 },
118 sounds
= mcl_sounds
.node_sound_defaults(),
119 on_construct
= function(pos
)
120 local meta
= minetest
.get_meta(pos
)
121 local inv
= meta
:get_inventory()
122 inv
:set_size("main", 1)
124 on_rightclick
= function(pos
, node
, clicker
, itemstack
)
125 if not itemstack
then
128 local meta
= minetest
.get_meta(pos
)
129 drop_item(pos
, node
, meta
)
130 local inv
= meta
:get_inventory()
131 if itemstack
:is_empty() then
132 remove_item_entity(pos
, node
)
133 meta
:set_string("infotext", "")
134 inv
:set_stack("main", 1, "")
137 local put_itemstack
= ItemStack(itemstack
)
138 put_itemstack
:set_count(1)
139 inv
:set_stack("main", 1, put_itemstack
)
140 update_item_entity(pos
, node
)
141 -- Add node infotext when item has been named
142 local imeta
= itemstack
:get_meta()
143 local iname
= imeta
:get_string("name")
145 meta
:set_string("infotext", iname
)
148 if not minetest
.settings
:get_bool("creative_mode") then
149 itemstack
:take_item()
153 on_destruct
= function(pos
)
154 local meta
= minetest
.get_meta(pos
)
155 local node
= minetest
.get_node(pos
)
156 drop_item(pos
, node
, meta
)
158 on_rotate
= on_rotate
,
161 minetest
.register_craft({
162 output
= 'mcl_itemframes:item_frame',
164 {'mcl_core:stick', 'mcl_core:stick', 'mcl_core:stick'},
165 {'mcl_core:stick', 'mcl_mobitems:leather', 'mcl_core:stick'},
166 {'mcl_core:stick', 'mcl_core:stick', 'mcl_core:stick'},
170 minetest
.register_lbm({
171 label
= "Update legacy item frames",
172 name
= "mcl_itemframes:update_legacy_item_frames",
173 nodenames
= {"itemframes:frame"},
174 action
= function(pos
, node
)
175 -- Swap legacy node, then respawn entity
176 node
.name
= "mcl_itemframes:item_frame"
177 local meta
= minetest
.get_meta(pos
)
178 local item
= meta
:get_string("item")
179 minetest
.swap_node(pos
, node
)
181 local itemstack
= ItemStack(minetest
.deserialize(meta
:get_string("itemdata")))
182 local inv
= meta
:get_inventory()
183 inv
:set_size("main", 1)
184 if not itemstack
:is_empty() then
185 inv
:set_stack("main", 1, itemstack
)
188 update_item_entity(pos
, node
)
192 minetest
.register_alias("itemframes:frame", "mcl_itemframes:item_frame")