2017-03-01 01:16:52 +01:00
local template = {
2017-12-11 16:28:28 +01:00
groups = { handy = 1 , axey = 1 , building_block = 1 , material_wood = 1 } ,
2017-03-01 01:16:52 +01:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
is_ground_content = true ,
_mcl_blast_resistance = 1 ,
_mcl_hardness = 0.2 ,
}
local red = table.copy ( template )
red.drop = {
items = {
{ items = { ' mcl_mushrooms:mushroom_red 1 ' } , rarity = 2 } ,
{ items = { ' mcl_mushrooms:mushroom_red 1 ' } , rarity = 2 } ,
}
}
local brown = table.copy ( template )
brown.drop = {
items = {
{ items = { ' mcl_mushrooms:mushroom_brown 1 ' } , rarity = 2 } ,
{ items = { ' mcl_mushrooms:mushroom_brown 1 ' } , rarity = 2 } ,
}
}
2017-12-11 16:28:28 +01:00
-- Convert a number to a string with 6 binary digits
local function to_binary ( num )
local binary = " "
while ( num > 0 ) do
local remainder_binary = ( num % 2 ) > 0 and 1 or 0
binary = binary .. remainder_binary
num = math.floor ( num / 2 )
end
binary = string.reverse ( binary )
while ( string.len ( binary ) < 6 ) do
binary = " 0 " .. binary
end
return binary
end
2017-03-01 01:16:52 +01:00
2017-12-11 16:28:28 +01:00
local register_mushroom = function ( color , species_id , template , d_cap , d_stem , d_stem_all , longdesc_cap , longdesc_stem )
2017-03-01 01:16:52 +01:00
2017-12-11 16:28:28 +01:00
-- Stem texture on all sides
2017-03-01 01:16:52 +01:00
local stem_full = table.copy ( template )
stem_full.description = d_stem_all
2017-12-11 16:28:28 +01:00
stem_full._doc_items_longdesc = " This decorative block is like a huge mushroom stem, but with the stem texture on all sides. "
2017-03-01 01:16:52 +01:00
stem_full.tiles = { " mcl_mushrooms_mushroom_block_skin_stem.png " }
2017-12-11 16:28:28 +01:00
stem_full.groups . huge_mushroom = species_id
stem_full.groups . huge_mushroom_stem = 2
2017-03-01 01:16:52 +01:00
minetest.register_node ( " mcl_mushrooms: " .. color .. " _mushroom_block_stem_full " , stem_full )
2017-12-11 16:28:28 +01:00
-- Stem
2017-03-01 01:16:52 +01:00
local stem = table.copy ( template )
stem.description = d_stem
2017-12-11 16:28:28 +01:00
stem._doc_items_longdesc = longdesc_stem
2017-03-01 01:16:52 +01:00
stem.tiles = { " mcl_mushrooms_mushroom_block_inside.png " , " mcl_mushrooms_mushroom_block_inside.png " , " mcl_mushrooms_mushroom_block_skin_stem.png " }
2017-12-11 16:28:28 +01:00
stem.groups . huge_mushroom = species_id
stem.groups . huge_mushroom_stem = 1
2017-03-01 01:16:52 +01:00
minetest.register_node ( " mcl_mushrooms: " .. color .. " _mushroom_block_stem " , stem )
2017-12-11 16:28:28 +01:00
-- Mushroom block (cap)
-- Each side can either be the cap or the pores texture.
-- Cubes have 6 sides, so there's a total of 2^6 = 64 combinations
for s = 0 , 63 do
local block = table.copy ( template )
local bin = to_binary ( s )
if s == 63 then
-- All-faces cap. This block is exposed to the player
block.description = d_cap
block._doc_items_longdesc = longdesc_cap
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. "
block.tiles = { " mcl_mushrooms_mushroom_block_skin_ " .. color .. " .png " }
block.on_construct = function ( pos )
local sides = {
{ { x = 0 , y = 1 , z = 0 } , 2 } ,
{ { x = 0 , y =- 1 , z = 0 } , 1 } ,
{ { x = 1 , y = 0 , z = 0 } , 4 } ,
{ { x =- 1 , y = 0 , z = 0 } , 3 } ,
{ { x = 0 , y = 0 , z = 1 } , 6 } ,
{ { x = 0 , y = 0 , z =- 1 } , 5 } ,
}
-- Replace the side of a mushroom node. Returns the new node.
-- Or nil, if unchanged.
local replace_side = function ( pos , node , side )
local bin = string.sub ( node.name , - 6 )
if string.sub ( bin , side , side ) == " 1 " then
local new_bin
if side == 1 then
new_bin = " 0 " .. string.sub ( bin , side + 1 , 6 )
elseif side == 6 then
new_bin = string.sub ( bin , 1 , side - 1 ) .. " 0 "
else
new_bin = string.sub ( bin , 1 , side - 1 ) .. " 0 " .. string.sub ( bin , side + 1 , 6 )
end
return { name = string.sub ( node.name , 1 , - 7 ) .. new_bin }
end
end
local node = minetest.get_node ( pos )
local species_self = minetest.get_item_group ( node.name , " huge_mushroom " )
local node_update = table.copy ( node )
for i = 1 , # sides do
local neighbor = vector.add ( pos , sides [ i ] [ 1 ] )
local neighbor_node = minetest.get_node ( neighbor )
local node_set = false
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
local i2 = sides [ i ] [ 2 ]
local node_return = replace_side ( pos , node_update , i )
if node_return then
node_update = node_return
node_set = true
end
local new_neighbor = replace_side ( neighbor , neighbor_node , i2 )
if new_neighbor then
minetest.set_node ( neighbor , new_neighbor )
end
end
if node_set then
minetest.set_node ( pos , node_update )
end
end
end
else
-- Cap block with pores on at least 1 side.
-- These blocks are used internally.
block._doc_items_create_entry = false
block.groups . not_in_creative_inventory = 1
block.groups . not_in_craft_guide = 1
block.tiles = { }
for t = 1 , string.len ( bin ) do
if string.sub ( bin , t , t ) == " 1 " then
block.tiles [ t ] = " mcl_mushrooms_mushroom_block_skin_ " .. color .. " .png "
else
block.tiles [ t ] = " mcl_mushrooms_mushroom_block_inside.png "
end
end
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_cap_111111 " , " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_cap_ " .. bin )
end
end
block.groups . huge_mushroom = species_id
block.groups . huge_mushroom_cap = s
-- bin is a binary string with 6 digits. Each digit stands for the
-- texture of one of the sides, in the same order as the tiles parameter.
-- 0 = pores; 1 = cap.
minetest.register_node ( " mcl_mushrooms: " .. color .. " _mushroom_block_cap_ " .. bin , block )
end
2017-03-01 01:16:52 +01:00
2017-03-20 18:12:05 +01:00
-- Add entry aliases for the Help
if minetest.get_modpath ( " doc " ) then
2017-09-08 23:07:39 +02:00
doc.add_entry_alias ( " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_cap_full " , " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_stem_full " )
doc.add_entry_alias ( " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_cap_full " , " nodes " , " mcl_mushrooms: " .. color .. " _mushroom_block_stem " )
2017-03-20 18:12:05 +01:00
end
2017-03-01 01:16:52 +01:00
end
2017-03-11 19:50:09 +01:00
2017-12-11 16:28:28 +01:00
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. "
local longdesc_red_stem = " The stem part of a huge red mushroom. "
register_mushroom ( " red " , 1 , red , " Huge Red Mushroom Block " , " Huge Red Mushroom Stem " , " Huge Red Mushroom All-Faces Stem " , longdesc_red )
2017-03-11 19:50:09 +01:00
2017-12-11 16:28:28 +01:00
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. "
local longdesc_brown_stem = " The stem part of a huge brown mushroom. "
register_mushroom ( " brown " , 2 , brown , " Huge Brown Mushroom Block " , " Huge Brown Mushroom Stem " , " Huge Brown Mushroom All-Faces Stem " , longdesc_brown )
2017-03-01 15:06:06 +01:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " group:huge_mushroom " ,
burntime = 15 ,
} )