Add a few v6-exclusive trades to villagers
[MineClone/MineClone2.git] / mods / ITEMS / mcl_mushrooms / huge.lua
bloba334a6387e3299c5d1d342c36d37e559343c992e
1 local template = {
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,
6 _mcl_hardness = 0.2,
9 local red = table.copy(template)
10 red.drop = {
11 items = {
12 { items = {'mcl_mushrooms:mushroom_red 1'}, rarity = 2 },
13 { items = {'mcl_mushrooms:mushroom_red 1'}, rarity = 2 },
17 local brown= table.copy(template)
18 brown.drop = {
19 items = {
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)
27 local binary = ""
28 while (num > 0) do
29 local remainder_binary = (num % 2) > 0 and 1 or 0
30 binary = binary .. remainder_binary
31 num = math.floor(num/2)
32 end
33 binary = string.reverse(binary)
34 while (string.len(binary) < 6) do
35 binary = "0" .. binary
36 end
37 return binary
38 end
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)
51 -- Stem
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
63 for s=0,63 do
64 local block = table.copy(template)
65 local bin = to_binary(s)
66 if s == 63 then
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)
74 local sides = {
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
88 local new_bin
89 if side == 1 then
90 new_bin = "0" .. string.sub(bin, side+1, 6)
91 elseif side == 6 then
92 new_bin = string.sub(bin, 1, side-1) .. "0"
93 else
94 new_bin = string.sub(bin, 1, side-1) .. "0" .. string.sub(bin, side+1, 6)
95 end
97 return { name = string.sub(node.name, 1, -7) .. new_bin }
98 end
99 end
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)
104 for i=1, #sides do
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)
112 if node_return then
113 node_update = node_return
114 node_set = true
116 local new_neighbor = replace_side(neighbor, neighbor_node, i2)
117 if new_neighbor then
118 minetest.set_node(neighbor, new_neighbor)
121 if node_set then
122 minetest.set_node(pos, node_update)
126 else
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
132 block.tiles = {}
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"
136 else
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({
168 type = "fuel",
169 recipe = "group:huge_mushroom",
170 burntime = 15,
173 -- Legacy support
174 local colors = { "red", "brown" }
175 for c=1, 2 do
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)
187 for c=1, 2 do
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"})
198 else
199 -- Fallback
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"})
211 else
212 -- Fallback
213 minetest.set_node(pos, {name = "mcl_mushrooms:"..color.."_mushroom_block_cap_101111"})
217 end,