2 groups
= {handy
=1,axey
=1, building_block
= 1, material_wood
= 1 },
3 sounds
= mcl_sounds
.node_sound_wood_defaults(),
4 is_ground_content
= true,
5 _mcl_blast_resistance
= 1,
9 local red
= table.copy(template
)
12 { items
= {'mcl_mushrooms:mushroom_red 1'}, rarity
= 2 },
13 { items
= {'mcl_mushrooms:mushroom_red 1'}, rarity
= 2 },
17 local brown
= table.copy(template
)
20 { items
= {'mcl_mushrooms:mushroom_brown 1'}, rarity
= 2 },
21 { items
= {'mcl_mushrooms:mushroom_brown 1'}, rarity
= 2 },
25 -- Convert a number to a string with 6 binary digits
26 local function to_binary(num
)
29 local remainder_binary
= (num
% 2) > 0 and 1 or 0
30 binary
= binary
.. remainder_binary
31 num
= math
.floor(num
/2)
33 binary
= string.reverse(binary
)
34 while (string.len(binary
) < 6) do
35 binary
= "0" .. binary
40 local register_mushroom
= function(color
, species_id
, template
, d_cap
, d_stem
, d_stem_all
, longdesc_cap
, longdesc_stem
)
42 -- Stem texture on all sides
43 local stem_full
= table.copy(template
)
44 stem_full
.description
= d_stem_all
45 stem_full
._doc_items_longdesc
= "This decorative block is like a huge mushroom stem, but with the stem texture on all sides."
46 stem_full
.tiles
= { "mcl_mushrooms_mushroom_block_skin_stem.png" }
47 stem_full
.groups
.huge_mushroom
= species_id
48 stem_full
.groups
.huge_mushroom_stem
= 2
49 minetest
.register_node("mcl_mushrooms:"..color
.."_mushroom_block_stem_full", stem_full
)
52 local stem
= table.copy(template
)
53 stem
.description
= d_stem
54 stem
._doc_items_longdesc
= longdesc_stem
55 stem
.tiles
= { "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_skin_stem.png" }
56 stem
.groups
.huge_mushroom
= species_id
57 stem
.groups
.huge_mushroom_stem
= 1
58 minetest
.register_node("mcl_mushrooms:"..color
.."_mushroom_block_stem", stem
)
60 -- Mushroom block (cap)
61 -- Each side can either be the cap or the pores texture.
62 -- Cubes have 6 sides, so there's a total of 2^6 = 64 combinations
64 local block
= table.copy(template
)
65 local bin
= to_binary(s
)
67 -- All-faces cap. This block is exposed to the player
68 block
.description
= d_cap
69 block
._doc_items_longdesc
= longdesc_cap
70 block
._doc_items_uagehelp
= "By placing huge mushroom blocks of the same species next to each other, the sides that touch each other will turn into pores permanently."
71 block
.tiles
= { "mcl_mushrooms_mushroom_block_skin_"..color
..".png" }
73 block
.on_construct
= function(pos
)
75 { { x
= 0, y
= 1, z
= 0 }, 2 },
76 { { x
= 0, y
=-1, z
= 0 }, 1 },
77 { { x
= 1, y
= 0, z
= 0 }, 4 },
78 { { x
=-1, y
= 0, z
= 0 }, 3 },
79 { { x
= 0, y
= 0, z
= 1 }, 6 },
80 { { x
= 0, y
= 0, z
=-1 }, 5 },
83 -- Replace the side of a mushroom node. Returns the new node.
84 -- Or nil, if unchanged.
85 local replace_side
= function(pos
, node
, side
)
86 local bin
= string.sub(node
.name
, -6)
87 if string.sub(bin
, side
, side
) == "1" then
90 new_bin
= "0" .. string.sub(bin
, side
+1, 6)
92 new_bin
= string.sub(bin
, 1, side
-1) .. "0"
94 new_bin
= string.sub(bin
, 1, side
-1) .. "0" .. string.sub(bin
, side
+1, 6)
97 return { name
= string.sub(node
.name
, 1, -7) .. new_bin
}
101 local node
= minetest
.get_node(pos
)
102 local species_self
= minetest
.get_item_group(node
.name
, "huge_mushroom")
103 local node_update
= table.copy(node
)
105 local neighbor
= vector
.add(pos
, sides
[i
][1])
106 local neighbor_node
= minetest
.get_node(neighbor
)
107 local node_set
= false
108 if minetest
.get_item_group(neighbor_node
.name
, "huge_mushroom_cap") ~= 0 and minetest
.get_item_group(neighbor_node
.name
, "huge_mushroom") == species_self
then
110 local i2
= sides
[i
][2]
111 local node_return
= replace_side(pos
, node_update
, i
)
113 node_update
= node_return
116 local new_neighbor
= replace_side(neighbor
, neighbor_node
, i2
)
118 minetest
.set_node(neighbor
, new_neighbor
)
122 minetest
.set_node(pos
, node_update
)
127 -- Cap block with pores on at least 1 side.
128 -- These blocks are used internally.
129 block
._doc_items_create_entry
= false
130 block
.groups
.not_in_creative_inventory
= 1
131 block
.groups
.not_in_craft_guide
= 1
133 for t
=1, string.len(bin
) do
134 if string.sub(bin
, t
, t
) == "1" then
135 block
.tiles
[t
] = "mcl_mushrooms_mushroom_block_skin_"..color
..".png"
137 block
.tiles
[t
] = "mcl_mushrooms_mushroom_block_inside.png"
141 if minetest
.get_modpath("doc") then
142 doc
.add_entry_alias("nodes", "mcl_mushrooms:"..color
.."_mushroom_block_cap_111111", "nodes", "mcl_mushrooms:"..color
.."_mushroom_block_cap_"..bin
)
146 block
.groups
.huge_mushroom
= species_id
147 block
.groups
.huge_mushroom_cap
= s
149 -- bin is a binary string with 6 digits. Each digit stands for the
150 -- texture of one of the sides, in the same order as the tiles parameter.
151 -- 0 = pores; 1 = cap.
152 minetest
.register_node("mcl_mushrooms:"..color
.."_mushroom_block_cap_"..bin
, block
)
158 local longdesc_red
= "Huge red mushroom blocks are the cap parts of huge red mushrooms. It consists of a red skin and can have pores on each of its sides."
159 local longdesc_red_stem
= "The stem part of a huge red mushroom."
160 register_mushroom("red", 1, red
, "Huge Red Mushroom Block", "Huge Red Mushroom Stem", "Huge Red Mushroom All-Faces Stem", longdesc_red
, longdesc_red_stem
)
163 local longdesc_brown
= "Huge brown mushroom blocks are the cap parts of huge brown mushrooms. It consists of a brown skin and can have pores on each of its sides."
164 local longdesc_brown_stem
= "The stem part of a huge brown mushroom."
165 register_mushroom("brown", 2, brown
, "Huge Brown Mushroom Block", "Huge Brown Mushroom Stem", "Huge Brown Mushroom All-Faces Stem", longdesc_brown
, longdesc_brown_stem
)
167 minetest
.register_craft({
169 recipe
= "group:huge_mushroom",
174 local colors
= { "red", "brown" }
176 local color
= colors
[c
]
177 minetest
.register_alias("mcl_mushrooms:"..color
.."_mushroom_block_cap_full", "mcl_mushrooms:"..color
.."_mushroom_block_cap_111111")
178 minetest
.register_alias("mcl_mushrooms:"..color
.."_mushroom_block_cap_top", "mcl_mushrooms:"..color
.."_mushroom_block_cap_100000")
179 minetest
.register_alias("mcl_mushrooms:"..color
.."_mushroom_block_pores_full", "mcl_mushrooms:"..color
.."_mushroom_block_cap_000000")
182 minetest
.register_lbm({
183 label
= "Replace legacy mushroom cap blocks",
184 name
= "mcl_mushrooms:replace_legacy_mushroom_caps",
185 nodenames
= { "mcl_mushrooms:brown_mushroom_block_cap_corner", "mcl_mushrooms:brown_mushroom_block_cap_side", "mcl_mushrooms:red_mushroom_block_cap_corner", "mcl_mushrooms:red_mushroom_block_cap_side" },
186 action
= function(pos
, node
)
188 local color
= colors
[c
]
189 if node
.name
== "mcl_mushrooms:"..color
.."_mushroom_block_cap_side" then
190 if node
.param2
== 0 then
191 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_100001"})
192 elseif node
.param2
== 1 then
193 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_100100"}) -- OK
194 elseif node
.param2
== 2 then
195 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_100010"})
196 elseif node
.param2
== 3 then
197 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_101000"})
200 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_101111"})
202 elseif node
.name
== "mcl_mushrooms:"..color
.."_mushroom_block_cap_corner" then
203 if node
.param2
== 0 then
204 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_101001"})
205 elseif node
.param2
== 1 then
206 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_100101"}) -- OK
207 elseif node
.param2
== 2 then
208 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_100110"}) -- OK
209 elseif node
.param2
== 3 then
210 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_101010"})
213 minetest
.set_node(pos
, {name
= "mcl_mushrooms:"..color
.."_mushroom_block_cap_101111"})