forked from VoxeLibre/VoxeLibre
294 lines
9.9 KiB
Lua
294 lines
9.9 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by michieal.
|
|
--- DateTime: 12/29/22 12:33 PM -- Restructure Date
|
|
---
|
|
|
|
-- LOCALS
|
|
local modname = minetest.get_current_modname()
|
|
local S = minetest.get_translator(modname)
|
|
local bamboo = "mcl_bamboo:bamboo"
|
|
local node_sound = mcl_sounds.node_sound_wood_defaults()
|
|
|
|
-- CONSTS
|
|
local DOUBLE_DROP_CHANCE = 8
|
|
local DEBUG = false
|
|
|
|
local strlen = string.len()
|
|
local substr = string.sub()
|
|
local rand = math.random()
|
|
|
|
-- basic bamboo nodes.
|
|
local bamboo_def = {
|
|
description = "Bamboo",
|
|
tiles = {"mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo.png"},
|
|
drawtype = "nodebox",
|
|
paramtype = "light",
|
|
groups = {handy = 1, axey = 1, choppy = 1, flammable = 3},
|
|
sounds = node_sound,
|
|
|
|
drop = {
|
|
max_items = 1,
|
|
-- Maximum number of item lists to drop.
|
|
-- The entries in 'items' are processed in order. For each:
|
|
-- Item filtering is applied, chance of drop is applied, if both are
|
|
-- successful the entire item list is dropped.
|
|
-- Entry processing continues until the number of dropped item lists
|
|
-- equals 'max_items'.
|
|
-- Therefore, entries should progress from low to high drop chance.
|
|
items = {
|
|
-- Examples:
|
|
{
|
|
-- 1 in 100 chance of dropping.
|
|
-- Default rarity is '1'.
|
|
rarity = DOUBLE_DROP_CHANCE,
|
|
items = {bamboo .. " 2"},
|
|
},
|
|
{
|
|
-- 1 in 2 chance of dropping.
|
|
-- Default rarity is '1'.
|
|
rarity = 1,
|
|
items = {bamboo},
|
|
},
|
|
},
|
|
},
|
|
|
|
inventory_image = "mcl_bamboo_bamboo_shoot.png",
|
|
wield_image = "mcl_bamboo_bamboo_shoot.png",
|
|
_mcl_blast_resistance = 1,
|
|
_mcl_hardness = 1.5,
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = {
|
|
{-0.175, -0.5, -0.195, 0.05, 0.5, 0.030},
|
|
}
|
|
},
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
if pointed_thing.type ~= "node" then
|
|
return itemstack
|
|
end
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
local pos = pointed_thing.under
|
|
if DEBUG then
|
|
minetest.log("mcl_bamboo::Node placement data:")
|
|
minetest.log(dump(pointed_thing))
|
|
minetest.log(dump(node))
|
|
end
|
|
|
|
if DEBUG then
|
|
minetest.log("mcl_bamboo::Checking for protected placement of bamboo.")
|
|
end
|
|
if mcl_bamboo.is_protected(pos, placer) then
|
|
return
|
|
end
|
|
if DEBUG then
|
|
minetest.log("mcl_bamboo::placement of bamboo is not protected.")
|
|
end
|
|
|
|
-- Use pointed node's on_rightclick function first, if present
|
|
if placer and not placer:get_player_control().sneak then
|
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
|
if DEBUG then
|
|
minetest.log("mcl_bamboo::attempting placement of bamboo via targeted node's on_rightclick.")
|
|
end
|
|
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
|
end
|
|
end
|
|
|
|
local mboo = substr(node.name, strlen(node.name) - 3, strlen(node.name))
|
|
|
|
if mboo ~= "mboo" and mboo ~= "oo_1" and mboo ~= "oo_2" and mboo ~= "oo_3" then
|
|
-- not bamboo...
|
|
if node.name ~= "mcl_flowerpots:flower_pot" then
|
|
local found = false
|
|
for i = 1, #mcl_bamboo.bamboo_dirt_nodes do
|
|
if node.name == mcl_bamboo.bamboo_dirt_nodes[i] then
|
|
found = true
|
|
break
|
|
end
|
|
end
|
|
if not found then
|
|
return itemstack
|
|
end
|
|
end
|
|
end
|
|
|
|
if DEBUG then
|
|
minetest.log("mcl_bamboo::placing bamboo directly.")
|
|
end
|
|
|
|
local place_item = table.copy(itemstack) -- make a copy so that we don't indirectly mess with the original.
|
|
|
|
if mboo == "mboo" then
|
|
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
elseif mboo ~= "oo_1" then
|
|
place_item:set_name(bamboo .. "_1")
|
|
itemstack:set_count(itemstack:get_count() - 1)
|
|
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
return itemstack, pointed_thing.under
|
|
elseif mboo ~= "oo_2" then
|
|
place_item:set_name(bamboo .. "_2")
|
|
itemstack:set_count(itemstack:get_count() - 1)
|
|
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
return itemstack, pointed_thing.under
|
|
elseif mboo ~= "oo_3" then
|
|
place_item:set_name(bamboo .. "_3")
|
|
itemstack:set_count(itemstack:get_count() - 1)
|
|
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
return itemstack, pointed_thing.under
|
|
else
|
|
local placed_type = rand(0, 3) -- randomly choose which one to place.
|
|
placed_type = rand(0, 3)
|
|
placed_type = rand(0, 3)
|
|
placed_type = rand(0, 3) -- Get the lua juices flowing. (Really, this is just to get it to give a real random number.)
|
|
if placed_type == 1 then
|
|
place_item:set_name(bamboo .. "_1")
|
|
end
|
|
if placed_type == 2 then
|
|
place_item:set_name(bamboo .. "_2")
|
|
end
|
|
if placed_type == 3 then
|
|
place_item:set_name(bamboo .. "_3")
|
|
end
|
|
itemstack:set_count(itemstack:get_count() - 1)
|
|
minetest.item_place(place_item, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
return itemstack, pointed_thing.under
|
|
end
|
|
end,
|
|
|
|
on_destruct = function(pos)
|
|
-- Node destructor; called before removing node.
|
|
local new_pos = vector.offset(pos, 0, 1, 0)
|
|
local node_above = minetest.get_node(new_pos)
|
|
local mboo = substr(node_above.name, strlen(node_above.name) - 3, strlen(node_above.name))
|
|
|
|
if node_above and (mboo == "mboo" or mboo == "oo_1" or mboo == "oo_2" or mboo == "oo_3") then
|
|
local sound_params = {
|
|
pos = new_pos,
|
|
gain = 1.0, -- default
|
|
max_hear_distance = 10, -- default, uses a Euclidean metric
|
|
}
|
|
minetest.remove_node(new_pos)
|
|
minetest.sound_play(node_sound.dug, sound_params, true)
|
|
local istack = ItemStack(bamboo)
|
|
if rand(1, DOUBLE_DROP_CHANCE) == 1 then
|
|
minetest.add_item(new_pos, istack)
|
|
end
|
|
minetest.add_item(new_pos, istack)
|
|
elseif node_above and node_above.name == "mcl_bamboo:bamboo_endcap" then
|
|
minetest.remove_node(new_pos)
|
|
minetest.sound_play(node_sound.dug, sound_params, true)
|
|
local istack = ItemStack(bamboo)
|
|
minetest.add_item(new_pos, istack)
|
|
if rand(1, DOUBLE_DROP_CHANCE) == 1 then
|
|
minetest.add_item(new_pos, istack)
|
|
end
|
|
end
|
|
end,
|
|
}
|
|
minetest.register_node(bamboo, bamboo_def)
|
|
|
|
local bamboo_top = table.copy(bamboo_def)
|
|
bamboo_top.groups = {not_in_creative_inventory = 1, handy = 1, axey = 1, choppy = 1, flammable = 3}
|
|
bamboo_top.tiles = {"mcl_bamboo_endcap.png"}
|
|
bamboo_top.drawtype = "plantlike"
|
|
bamboo_top.paramtype2 = "meshoptions"
|
|
bamboo_top.param2 = 34
|
|
bamboo_top.nodebox = nil
|
|
|
|
bamboo_top.on_place = function(itemstack, _, _)
|
|
-- Should never occur... but, if it does, then nix it.
|
|
itemstack:set_name(bamboo)
|
|
return itemstack
|
|
end
|
|
|
|
minetest.register_node("mcl_bamboo:bamboo_endcap", bamboo_top)
|
|
|
|
local bamboo_block_def = {
|
|
description = "Bamboo Block",
|
|
tiles = {"mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_block.png"},
|
|
groups = {handy = 1, building_block = 1, axey = 1, flammable = 2, material_wood = 1, bamboo_block = 1, fire_encouragement = 5, fire_flammability = 5},
|
|
sounds = node_sound,
|
|
paramtype2 = "facedir",
|
|
drops = "mcl_bamboo:bamboo_block",
|
|
_mcl_blast_resistance = 3,
|
|
_mcl_hardness = 2,
|
|
_mcl_stripped_variant = "mcl_bamboo:bamboo_block_stripped", -- this allows us to use the built in Axe's strip block.
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
local pos = pointed_thing.under
|
|
|
|
if mcl_bamboo.is_protected(pos, placer) then
|
|
return
|
|
end
|
|
|
|
-- Use pointed node's on_rightclick function first, if present
|
|
local node = minetest.get_node(pointed_thing.under)
|
|
if placer and not placer:get_player_control().sneak then
|
|
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
|
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
|
|
end
|
|
end
|
|
|
|
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
|
|
end,
|
|
|
|
}
|
|
|
|
minetest.register_node("mcl_bamboo:bamboo_block", bamboo_block_def)
|
|
|
|
local bamboo_stripped_block = table.copy(bamboo_block_def)
|
|
bamboo_stripped_block.on_rightclick = nil
|
|
bamboo_stripped_block.description = S("Stripped Bamboo Block")
|
|
bamboo_stripped_block.tiles = {"mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_bottom.png", "mcl_bamboo_bamboo_block_stripped.png"}
|
|
minetest.register_node("mcl_bamboo:bamboo_block_stripped", bamboo_stripped_block)
|
|
minetest.register_node("mcl_bamboo:bamboo_plank", {
|
|
description = S("Bamboo Plank"),
|
|
_doc_items_longdesc = S("Bamboo Plank"),
|
|
_doc_items_hidden = false,
|
|
tiles = {"mcl_bamboo_bamboo_plank.png"},
|
|
stack_max = 64,
|
|
is_ground_content = false,
|
|
groups = {handy = 1, axey = 1, flammable = 3, wood = 1, building_block = 1, material_wood = 1, fire_encouragement = 5, fire_flammability = 20},
|
|
sounds = mcl_sounds.node_sound_wood_defaults(),
|
|
_mcl_blast_resistance = 3,
|
|
_mcl_hardness = 2,
|
|
})
|
|
|
|
-- Bamboo Part 2 Base nodes.
|
|
-- Bamboo alternative node types.
|
|
local def = minetest.registered_nodes [bamboo]
|
|
def.node_box = {
|
|
type = "fixed",
|
|
fixed = {
|
|
{-0.05, -0.5, 0.285, -0.275, 0.5, 0.06},
|
|
}
|
|
}
|
|
minetest.register_node(bamboo.."_1", def)
|
|
|
|
def.node_box = {
|
|
type = "fixed",
|
|
fixed = {
|
|
{0.25, -0.5, 0.325, 0.025, 0.5, 0.100},
|
|
}
|
|
}
|
|
minetest.register_node(bamboo.."_2", def)
|
|
|
|
def.node_box = {
|
|
type = "fixed",
|
|
fixed = {
|
|
{-0.125, -0.5, 0.125, -0.3125, 0.5, 0.3125},
|
|
}
|
|
}
|
|
minetest.register_node(bamboo.."_3", def)
|
|
|
|
-- Bamboo Mosaic
|
|
local bamboo_mosaic = minetest.registered_nodes[bamboo .. "_plank"]
|
|
bamboo_mosaic.tiles = {"mcl_bamboo_bamboo_plank.png"}
|
|
bamboo_mosaic.groups = {handy = 1, axey = 1, flammable = 3, fire_encouragement = 5, fire_flammability = 20}
|
|
bamboo_mosaic.description = S("Bamboo Mosaic Plank")
|
|
bamboo_mosaic._doc_items_longdesc = S("Bamboo Mosaic Plank")
|
|
minetest.register_node("mcl_bamboo:bamboo_mosaic", bamboo_mosaic)
|
|
|