1
0
Fork 0

Added full node names for bamboo on_place.

Added in bamboo top destruct.
Removed mapgen.lua.
This commit is contained in:
Michieal 2022-12-21 22:22:51 -05:00
parent 9445b02dcc
commit 2b11b5c17a
2 changed files with 46 additions and 82 deletions

View File

@ -8,12 +8,7 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local S = minetest.get_translator(modname) local S = minetest.get_translator(modname)
local bamboo = "mcl_bamboo:bamboo" local bamboo = "mcl_bamboo:bamboo"
local adj_nodes = {
vector.new(0, 0, 1),
vector.new(0, 0, -1),
vector.new(1, 0, 0),
vector.new(-1, 0, 0),
}
local node_sound = mcl_sounds.node_sound_wood_defaults() local node_sound = mcl_sounds.node_sound_wood_defaults()
-- CONSTS -- CONSTS
@ -126,7 +121,14 @@ local function create_nodes()
if node.name ~= "mcl_bamboo:bamboo" then if node.name ~= "mcl_bamboo:bamboo" then
if node.name ~= "mcl_flowerpots:flower_pot" then if node.name ~= "mcl_flowerpots:flower_pot" then
if minetest.get_item_group(node.name, "dirt") == 0 then local found = false
for i = 1, #bamboo_dirt_nodes do
if node.name == bamboo_dirt_nodes[i] then
found = true
break
end
end
if not found then
return itemstack return itemstack
end end
end end
@ -143,13 +145,18 @@ local function create_nodes()
-- Node destructor; called before removing node. -- Node destructor; called before removing node.
local new_pos = vector.offset(pos, 0, 1, 0) local new_pos = vector.offset(pos, 0, 1, 0)
local node_above = minetest.get_node(new_pos) local node_above = minetest.get_node(new_pos)
if node_above and node_above.name == "mcl_bamboo:bamboo" then if node_above and node_above.name == bamboo then
local sound_params = { local sound_params = {
pos = new_pos, pos = new_pos,
gain = 1.0, -- default gain = 1.0, -- default
max_hear_distance = 10, -- default, uses a Euclidean metric 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("mcl_bamboo:bamboo")
minetest.add_item(new_pos, istack)
elseif node_above and node_above.name == "mcl_bamboo:bamboo_endcap" then
minetest.remove_node(new_pos) minetest.remove_node(new_pos)
minetest.sound_play(node_sound.dug, sound_params, true) minetest.sound_play(node_sound.dug, sound_params, true)
local istack = ItemStack("mcl_bamboo:bamboo") local istack = ItemStack("mcl_bamboo:bamboo")
@ -157,9 +164,10 @@ local function create_nodes()
end end
end, end,
} }
minetest.register_node("mcl_bamboo:bamboo", bamboo_def) minetest.register_node(bamboo, bamboo_def)
local bamboo_top = table.copy(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.groups = {not_in_creative_inventory = 1, handy = 1, axey = 1, choppy = 1, flammable = 3}
bamboo_top.drops = bamboo
bamboo_top.on_place = function(itemstack, placer, pointed_thing) bamboo_top.on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
@ -200,7 +208,26 @@ local function create_nodes()
minetest.log("mcl_bamboo::placing bamboo directly.") minetest.log("mcl_bamboo::placing bamboo directly.")
end end
return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under))) return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(vector.direction(pointed_thing.above, pointed_thing.under)))
end, end
--[[
bamboo_top.on_destruct = function(pos)
-- Node destructor; called before removing node.
local node = minetest.get_node(pos)
if node and node.name == "mcl_bamboo:bamboo_endcap" then
local sound_params = {
pos = pos,
gain = 1.0, -- default
max_hear_distance = 10, -- default, uses a Euclidean metric
}
minetest.remove_node(pos)
minetest.sound_play(node_sound.dug, sound_params, true)
local istack = ItemStack("mcl_bamboo:bamboo")
minetest.add_item(pos, istack)
end
end
]]
minetest.register_node("mcl_bamboo:bamboo_endcap", bamboo_top) minetest.register_node("mcl_bamboo:bamboo_endcap", bamboo_top)
@ -732,9 +759,6 @@ end
create_nodes() create_nodes()
register_craftings() register_craftings()
-- MAPGEN
dofile(minetest.get_modpath(modname) .. "/mapgen.lua")
-- BAMBOO_TOO (Bamboo two) -- BAMBOO_TOO (Bamboo two)
dofile(minetest.get_modpath(modname) .. "/bambootoo.lua") dofile(minetest.get_modpath(modname) .. "/bambootoo.lua")
@ -745,8 +769,8 @@ minetest.register_abm({
nodenames = {"mcl_bamboo:bamboo"}, nodenames = {"mcl_bamboo:bamboo"},
interval = 40, interval = 40,
chance = 40, chance = 40,
action = function(pos, node) action = function(pos, _)
local soil_pos = nil local soil_pos
if minetest.get_node_light(pos) < 8 then if minetest.get_node_light(pos) < 8 then
return return
end end

View File

@ -1,60 +0,0 @@
local item_water, item_dirt, item_grass
item_water = "mcl_core:water_source"
item_dirt = "mcl_core:dirt"
item_grass = "mcl_core:dirt_with_grass"
local function make_bamboo(pos, size)
for y = 0, size - 1 do
local p = {x = pos.x, y = pos.y + y, z = pos.z}
if minetest.get_node(p).name ~= "air" then
return
end
minetest.set_node(p, {name = "mcl_bamboo:bamboo"})
end
end
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y < 2 and minp.y > 0 then
return
end
local c_grass = minetest.get_content_id(item_grass)
local n_bamboo = minetest.get_perlin(8234, 3, 0.6, 100)
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(minp, maxp)
local area = VoxelArea:new {MinEdge = emin, MaxEdge = emax}
local data = vm:get_data()
local rand = PseudoRandom(seed % 8000)
for z = minp.z + 2, maxp.z - 2, 4 do
for x = minp.x + 2, maxp.x - 2, 4 do
local bamboo_amount = math.floor(n_bamboo:get_2d({x = x, y = z}) * 7 - 3)
for i = 1, bamboo_amount do
local p_pos = {
x = rand:next(x - 2, x + 2),
y = 0,
z = rand:next(z - 2, z + 2)
}
local found = false
local node = -1
for y = 4, 0, -1 do
p_pos.y = y
node = data[area:index(p_pos.x, p_pos.y, p_pos.z)]
if node == c_grass then
found = true
break
end
end
if found and
minetest.find_node_near(p_pos, 5, {"group:water", item_water}) then
p_pos.y = p_pos.y + 1
make_bamboo(p_pos, rand:next(4, 12))
end
end
end
end
end
)