1 -- TODO: Move all textures to mcl_paintings when finished
4 local MP
= minetest
.get_modpath(minetest
.get_current_modname())
5 local S
, NS
= dofile(MP
.. "/intllib.lua")
7 minetest
.register_craftitem("mcl_paintings:painting", {
8 description
= S("Painting"),
9 _doc_items_longdesc
= S("Paintings are decorations which can be placed on walls. THIS ITEM IS INCOMPLETE."),
10 wield_image
= "gemalde_node.png",
11 inventory_image
= "gemalde_node.png",
12 on_place
= function(itemstack
, placer
, pointed_thing
)
13 if pointed_thing
.type ~= "node" then
17 local under
= pointed_thing
.under
18 local above
= pointed_thing
.above
20 -- Use pointed node's on_rightclick function first, if present
21 local node_under
= minetest
.get_node(under
)
22 if placer
and not placer
:get_player_control().sneak
then
23 if minetest
.registered_nodes
[node_under
.name
] and minetest
.registered_nodes
[node_under
.name
].on_rightclick
then
24 return minetest
.registered_nodes
[node_under
.name
].on_rightclick(under
, node_under
, placer
, itemstack
) or itemstack
28 -- Can only be placed on side
29 if under
.y
~= above
.y
then
32 -- Can only be placed on solid nodes
33 if minetest
.get_item_group(node_under
.name
, "solid") == 0 then
37 -- Spawn painting and rotate
38 local painting
= minetest
.add_entity(above
, "mcl_paintings:painting")
39 local yaw
= minetest
.dir_to_yaw(vector
.direction(under
, above
))
42 if not minetest
.settings
:get_bool("creative_mode") then
49 -- List of painting IDs, indexed by size.
50 -- Outer index: Width in node lengths
51 -- Inner index: Height in node lengths
54 [1] = { 1, 2, 3, 4, 5, 6, 7 }, -- 1×1
55 [2] = { 8, 9, 10, 11, 12 }, -- 1×2
58 [1] = { 13, 14}, -- 2×1
59 [2] = { 15, 16, 17, 18, 19, 20 }, -- 2×2
62 [4] = { 25, 26 }, -- 3×4
66 [4] = { 22, 23, 24 }, -- 4×4
70 -- Returns a random painting ID for the given size.
71 -- x: Width in node lenghts
72 -- y: Height in node lengths
73 local function select_painting(x
, y
)
75 local pool
= paintings
[x
][y
]
76 if paintings
[x
][y
] then
77 local p
= math
.random(1, #pool
)
84 -- Returns the texture table for the given painting ID
85 local get_textures
= function(painting_id
)
91 "gemalde_"..tostring(painting_id
)..".png",
98 -- Breaks and drops as item if punched.
100 minetest
.register_entity("mcl_paintings:painting", {
102 collide_with_objects
= true,
106 visual_size
= { x
=1, y
=1 },
107 textures
= get_textures(1),
109 _painting
= nil, -- Holds the current painting ID. Initially nil for random painting
111 get_staticdata
= function(self
)
112 local out
= { _painting
= self
._painting
}
113 return minetest
.serialize(out
)
115 on_activate
= function(self
, staticdata
)
116 if staticdata
and staticdata
~= "" then
117 local inp
= minetest
.deserialize(staticdata
)
118 self
._painting
= inp
._painting
120 -- Initial spawn. Select random painting
121 if not self
._painting
then
122 self
._painting
= select_painting(1, 1)
124 self
.object
:set_properties({textures
= get_textures(self
._painting
)})
126 on_punch
= function(self
, puncher
)
127 if not puncher
or not puncher
:is_player() or self
._removed
then
130 -- Drop painting as item on ground
131 if not minetest
.settings
:get_bool("creative_mode") then
132 minetest
.add_item(self
.object
:getpos(), "mcl_paintings:painting")
140 -- TODO: Add crafting when this mod works better
141 if minetest.get_modpath("mcl_core") then
142 minetest.register_craft({
143 output = "mcl_paintings:painting",
145 {"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
146 {"mcl_core:stick", "group:wool", "mcl_core:stick"},
147 {"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},