forked from MineClone5/MineClone5
Allow pores on each side of huge mushroom caps
Also automatically create porse when placing cap blocks next to each other. Node names are changed.
This commit is contained in:
parent
759a9524fc
commit
a82610fef1
|
@ -1,5 +1,5 @@
|
|||
local template = {
|
||||
groups = {handy=1,axey=1, huge_mushroom = 1, building_block = 1, not_in_creative_inventory = 1, not_in_craft_guide=1, material_wood = 1 },
|
||||
groups = {handy=1,axey=1, building_block = 1, material_wood = 1 },
|
||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
||||
is_ground_content = true,
|
||||
_mcl_blast_resistance = 1,
|
||||
|
@ -22,82 +22,153 @@ brown.drop = {
|
|||
}
|
||||
}
|
||||
|
||||
local register_mushroom = function(color, template, d_cap_top, d_cap_side, d_cap_corner, d_stem, d_pores, d_cap_all, d_stem_all, doc_items_entry_name, doc_items_longdesc)
|
||||
-- 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
|
||||
|
||||
-- DV (Minecraft dava value) 14: Cap texture on all sides
|
||||
local full = table.copy(template)
|
||||
full.description = d_cap_all
|
||||
full._doc_items_entry_name = doc_items_entry_name
|
||||
full._doc_items_longdesc = doc_items_longdesc
|
||||
full.tiles = { "mcl_mushrooms_mushroom_block_skin_"..color..".png" }
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_cap_full", full)
|
||||
local register_mushroom = function(color, species_id, template, d_cap, d_stem, d_stem_all, longdesc_cap, longdesc_stem)
|
||||
|
||||
-- DV 0: Pores on all sides
|
||||
local pores_full = table.copy(template)
|
||||
pores_full.description = d_pores
|
||||
pores_full._doc_items_create_entry = false
|
||||
pores_full.tiles = { "mcl_mushrooms_mushroom_block_inside.png" }
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_pores_full", pores_full)
|
||||
|
||||
-- DV 15: Stem texture on all sides
|
||||
-- Stem texture on all sides
|
||||
local stem_full = table.copy(template)
|
||||
stem_full.description = d_stem_all
|
||||
stem_full._doc_items_create_entry = false
|
||||
stem_full._doc_items_longdesc = "This decorative block is like a huge mushroom stem, but with the stem texture on all sides."
|
||||
stem_full.tiles = { "mcl_mushrooms_mushroom_block_skin_stem.png" }
|
||||
stem_full.groups.huge_mushroom = species_id
|
||||
stem_full.groups.huge_mushroom_stem = 2
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_stem_full", stem_full)
|
||||
|
||||
-- DV 10: Stem
|
||||
-- Stem
|
||||
local stem = table.copy(template)
|
||||
stem.description = d_stem
|
||||
stem._doc_items_create_entry = false
|
||||
stem._doc_items_longdesc = longdesc_stem
|
||||
stem.tiles = { "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_skin_stem.png" }
|
||||
stem.groups.huge_mushroom = species_id
|
||||
stem.groups.huge_mushroom_stem = 1
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_stem", stem)
|
||||
|
||||
-- DV 1, DV 3, DV 7, DV 9: Cap corner. Cap texture on top and two sides in a corner formation
|
||||
local cap_corner = table.copy(template)
|
||||
cap_corner.description = d_cap_corner
|
||||
cap_corner._doc_items_create_entry = false
|
||||
cap_corner.paramtype2 = "facedir"
|
||||
cap_corner.tiles = { "mcl_mushrooms_mushroom_block_skin_"..color..".png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_skin_"..color..".png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_skin_"..color..".png" }
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_cap_corner", cap_corner)
|
||||
-- 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" }
|
||||
|
||||
-- DV 5: Cap texture on top
|
||||
local cap_top = table.copy(template)
|
||||
cap_top.description = d_cap_top
|
||||
cap_top._doc_items_create_entry = false
|
||||
cap_top.tiles = { "mcl_mushrooms_mushroom_block_skin_"..color..".png", "mcl_mushrooms_mushroom_block_inside.png" }
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_cap_top", cap_top)
|
||||
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 },
|
||||
}
|
||||
|
||||
-- DV 2, DV 4, DV 6, DV 8: Cap texture on top and one side
|
||||
local cap_side = table.copy(template)
|
||||
cap_side.description = d_cap_side
|
||||
cap_side._doc_items_create_entry = false
|
||||
cap_side.paramtype2 = "facedir"
|
||||
cap_side.tiles = { "mcl_mushrooms_mushroom_block_skin_"..color..".png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_inside.png", "mcl_mushrooms_mushroom_block_skin_"..color..".png" }
|
||||
minetest.register_node("mcl_mushrooms:"..color.."_mushroom_block_cap_side", cap_side)
|
||||
-- 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
|
||||
|
||||
-- Add entry aliases for the Help
|
||||
if minetest.get_modpath("doc") then
|
||||
doc.add_entry_alias("nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_full", "nodes", "mcl_mushrooms:"..color.."_mushroom_block_pores_full")
|
||||
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")
|
||||
doc.add_entry_alias("nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_full", "nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_corner")
|
||||
doc.add_entry_alias("nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_full", "nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_top")
|
||||
doc.add_entry_alias("nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_full", "nodes", "mcl_mushrooms:"..color.."_mushroom_block_cap_side")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local longdesc_red = "Huge red mushroom blocks are the plant parts of huge red mushrooms. This includes caps, pores and stems of huge red mushrooms; and these blocks come in some variants."
|
||||
local entry_name_red = "Huge Red Mushroom Block"
|
||||
|
||||
register_mushroom("red", red, "Huge Red Mushroom Cap Top", "Huge Red Mushroom Cap Side", "Huge Red Mushroom Cap Corner", "Huge Red Mushroom Stem", "Huge Red Mushroom Pores", "Huge Red Mushroom All-Faces Cap", "Huge Red Mushroom All-Faces Stem", entry_name_red, longdesc_red)
|
||||
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)
|
||||
|
||||
|
||||
local longdesc_brown = "Huge brown mushroom blocks are the plant parts of huge brown mushrooms. This includes caps, pores and stems of huge brown mushrooms; and these blocks come in some variants."
|
||||
local entry_name_brown = "Huge Brown Mushroom Block"
|
||||
|
||||
register_mushroom("brown", brown, "Huge Brown Mushroom Cap Top", "Huge Brown Mushroom Cap Side", "Huge Brown Mushroom Cap Corner", "Huge Brown Mushroom Stem", "Huge Brown Mushroom Pores", "Huge Brown Mushroom All-Faces Cap", "Huge Brown Mushroom All-Faces Stem", entry_name_brown, longdesc_brown)
|
||||
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)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
|
|
Loading…
Reference in New Issue