mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-28 18:50:27 +01:00
fix missing function in default game, issue https://github.com/MinetestForFun/server-minetestforfun/issues/504
This commit is contained in:
parent
a5ea62d1ac
commit
34a28db177
@ -995,6 +995,23 @@ minetest.register_node("default:aspen_sapling", {
|
|||||||
groups = {snappy = 2, dig_immediate = 3, flammable = 2,
|
groups = {snappy = 2, dig_immediate = 3, flammable = 2,
|
||||||
attached_node = 1, sapling = 1},
|
attached_node = 1, sapling = 1},
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
sounds = default.node_sound_leaves_defaults(),
|
||||||
|
|
||||||
|
on_construct = function(pos)
|
||||||
|
minetest.get_node_timer(pos):start(math.random(2400,4800))
|
||||||
|
end,
|
||||||
|
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
itemstack = default.sapling_on_place(itemstack, placer, pointed_thing,
|
||||||
|
"default:aspen_sapling",
|
||||||
|
-- minp, maxp to be checked, relative to sapling pos
|
||||||
|
-- minp_relative.y = 1 because sapling pos has been checked
|
||||||
|
{x = -2, y = 1, z = -2},
|
||||||
|
{x = 2, y = 12, z = 2},
|
||||||
|
-- maximum interval of interior volume check
|
||||||
|
4)
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- From BFD, cherry tree
|
-- From BFD, cherry tree
|
||||||
@ -1557,7 +1574,8 @@ minetest.register_node("default:dry_grass_1", {
|
|||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
buildable_to = true,
|
buildable_to = true,
|
||||||
groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1, dry_grass = 1},
|
groups = {snappy = 3, flammable = 3, flora = 1,
|
||||||
|
attached_node = 1, dry_grass = 1},
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
sounds = default.node_sound_leaves_defaults(),
|
||||||
selection_box = {
|
selection_box = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
@ -1585,8 +1603,8 @@ for i = 2, 5 do
|
|||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
walkable = false,
|
walkable = false,
|
||||||
buildable_to = true,
|
buildable_to = true,
|
||||||
groups = {snappy = 3, flammable = 3, flora = 1,
|
groups = {snappy = 3, flammable = 3, flora = 1, attached_node = 1,
|
||||||
attached_node = 1, not_in_creative_inventory=1, dry_grass = 1},
|
not_in_creative_inventory=1, dry_grass = 1},
|
||||||
drop = "default:dry_grass_1",
|
drop = "default:dry_grass_1",
|
||||||
sounds = default.node_sound_leaves_defaults(),
|
sounds = default.node_sound_leaves_defaults(),
|
||||||
selection_box = {
|
selection_box = {
|
||||||
|
@ -27,90 +27,72 @@ end
|
|||||||
-- 'is snow nearby' function
|
-- 'is snow nearby' function
|
||||||
|
|
||||||
local function is_snow_nearby(pos)
|
local function is_snow_nearby(pos)
|
||||||
local x, y, z = pos.x, pos.y, pos.z
|
return #minetest.find_nodes_in_area(
|
||||||
local c_snow = minetest.get_content_id("default:snow")
|
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
|
||||||
local c_snowblock = minetest.get_content_id("default:snowblock")
|
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
|
||||||
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
|
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) > 0
|
||||||
|
|
||||||
local vm = minetest.get_voxel_manip()
|
|
||||||
local minp, maxp = vm:read_from_map(
|
|
||||||
{x = x - 1, y = y - 1, z = z - 1},
|
|
||||||
{x = x + 1, y = y + 1, z = z + 1}
|
|
||||||
)
|
|
||||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
|
||||||
local data = vm:get_data()
|
|
||||||
|
|
||||||
for yy = y - 1, y + 1 do
|
|
||||||
for zz = z - 1, z + 1 do
|
|
||||||
local vi = a:index(x - 1, yy, zz)
|
|
||||||
for xx = x - 1, x + 1 do
|
|
||||||
local nodid = data[vi]
|
|
||||||
if nodid == c_snow or nodid == c_snowblock or nodid == c_dirtsnow then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
vi = vi + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Sapling ABM
|
-- Sapling ABM
|
||||||
|
|
||||||
minetest.register_abm({
|
function default.grow_sapling(pos)
|
||||||
nodenames = {"default:sapling", "default:junglesapling",
|
if not default.can_grow(pos) then
|
||||||
"default:pine_sapling", "default:acacia_sapling",
|
-- try a bit later again
|
||||||
"default:aspen_sapling"},
|
minetest.get_node_timer(pos):start(math.random(240, 600))
|
||||||
interval = 10,
|
return
|
||||||
chance = 50,
|
end
|
||||||
action = function(pos, node)
|
|
||||||
if not default.can_grow(pos) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local mapgen = minetest.get_mapgen_params().mgname
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||||
if node.name == "default:sapling" then
|
local node = minetest.get_node(pos)
|
||||||
minetest.log("action", "A sapling grows into a tree at "..
|
if node.name == "default:sapling" then
|
||||||
minetest.pos_to_string(pos))
|
minetest.log("action", "A sapling grows into a tree at "..
|
||||||
if mapgen == "v6" then
|
minetest.pos_to_string(pos))
|
||||||
default.grow_tree(pos, random(1, 4) == 1)
|
if mg_name == "v6" then
|
||||||
else
|
default.grow_tree(pos, random(1, 4) == 1)
|
||||||
default.grow_new_apple_tree(pos)
|
else
|
||||||
end
|
default.grow_new_apple_tree(pos)
|
||||||
elseif node.name == "default:junglesapling" then
|
|
||||||
minetest.log("action", "A jungle sapling grows into a tree at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
if mapgen == "v6" then
|
|
||||||
default.grow_jungle_tree(pos)
|
|
||||||
else
|
|
||||||
default.grow_new_jungle_tree(pos)
|
|
||||||
end
|
|
||||||
elseif node.name == "default:pine_sapling" then
|
|
||||||
minetest.log("action", "A pine sapling grows into a tree at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
local snow = is_snow_nearby(pos)
|
|
||||||
if mapgen == "v6" then
|
|
||||||
default.grow_pine_tree(pos, snow)
|
|
||||||
elseif snow then
|
|
||||||
default.grow_new_snowy_pine_tree(pos)
|
|
||||||
else
|
|
||||||
default.grow_new_pine_tree(pos)
|
|
||||||
end
|
|
||||||
elseif node.name == "default:acacia_sapling" then
|
|
||||||
minetest.log("action", "An acacia sapling grows into a tree at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
default.grow_new_acacia_tree(pos)
|
|
||||||
elseif node.name == "default:aspen_sapling" then
|
|
||||||
minetest.log("action", "An aspen sapling grows into a tree at "..
|
|
||||||
minetest.pos_to_string(pos))
|
|
||||||
default.grow_new_aspen_tree(pos)
|
|
||||||
end
|
end
|
||||||
|
elseif node.name == "default:junglesapling" then
|
||||||
|
minetest.log("action", "A jungle sapling grows into a tree at "..
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
if mg_name == "v6" then
|
||||||
|
default.grow_jungle_tree(pos)
|
||||||
|
else
|
||||||
|
default.grow_new_jungle_tree(pos)
|
||||||
|
end
|
||||||
|
elseif node.name == "default:pine_sapling" then
|
||||||
|
minetest.log("action", "A pine sapling grows into a tree at "..
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
local snow = is_snow_nearby(pos)
|
||||||
|
if mg_name == "v6" then
|
||||||
|
default.grow_pine_tree(pos, snow)
|
||||||
|
elseif snow then
|
||||||
|
default.grow_new_snowy_pine_tree(pos)
|
||||||
|
else
|
||||||
|
default.grow_new_pine_tree(pos)
|
||||||
|
end
|
||||||
|
elseif node.name == "default:acacia_sapling" then
|
||||||
|
minetest.log("action", "An acacia sapling grows into a tree at "..
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
default.grow_new_acacia_tree(pos)
|
||||||
|
elseif node.name == "default:aspen_sapling" then
|
||||||
|
minetest.log("action", "An aspen sapling grows into a tree at "..
|
||||||
|
minetest.pos_to_string(pos))
|
||||||
|
default.grow_new_aspen_tree(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
name = "default:convert_saplings_to_node_timer",
|
||||||
|
nodenames = {"default:sapling", "default:junglesapling",
|
||||||
|
"default:pine_sapling", "default:acacia_sapling",
|
||||||
|
"default:aspen_sapling"},
|
||||||
|
action = function(pos)
|
||||||
|
minetest.get_node_timer(pos):start(math.random(1200, 2400))
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Tree generation
|
-- Tree generation
|
||||||
--
|
--
|
||||||
@ -194,8 +176,8 @@ function default.grow_tree(pos, is_apple_tree, bad)
|
|||||||
|
|
||||||
local vm = minetest.get_voxel_manip()
|
local vm = minetest.get_voxel_manip()
|
||||||
local minp, maxp = vm:read_from_map(
|
local minp, maxp = vm:read_from_map(
|
||||||
{x = pos.x - 2, y = pos.y, z = pos.z - 2},
|
{x = x - 2, y = y, z = z - 2},
|
||||||
{x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2}
|
{x = x + 2, y = y + height + 1, z = z + 2}
|
||||||
)
|
)
|
||||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
@ -229,8 +211,8 @@ function default.grow_jungle_tree(pos, bad)
|
|||||||
|
|
||||||
local vm = minetest.get_voxel_manip()
|
local vm = minetest.get_voxel_manip()
|
||||||
local minp, maxp = vm:read_from_map(
|
local minp, maxp = vm:read_from_map(
|
||||||
{x = pos.x - 3, y = pos.y - 1, z = pos.z - 3},
|
{x = x - 3, y = y - 1, z = z - 3},
|
||||||
{x = pos.x + 3, y = pos.y + height + 1, z = pos.z + 3}
|
{x = x + 3, y = y + height + 1, z = z + 3}
|
||||||
)
|
)
|
||||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
@ -436,6 +418,7 @@ function default.grow_new_acacia_tree(pos)
|
|||||||
path, "random", nil, false)
|
path, "random", nil, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- New aspen tree
|
-- New aspen tree
|
||||||
|
|
||||||
function default.grow_new_aspen_tree(pos)
|
function default.grow_new_aspen_tree(pos)
|
||||||
@ -445,6 +428,53 @@ function default.grow_new_aspen_tree(pos)
|
|||||||
path, "0", nil, false)
|
path, "0", nil, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Sapling 'on place' function to check protection of node and resulting tree volume
|
||||||
|
--
|
||||||
|
|
||||||
|
function default.sapling_on_place(itemstack, placer, pointed_thing,
|
||||||
|
sapling_name, minp_relative, maxp_relative, interval)
|
||||||
|
-- Position of sapling
|
||||||
|
local pos = pointed_thing.under
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local pdef = minetest.registered_nodes[node.name]
|
||||||
|
if not pdef or not pdef.buildable_to then
|
||||||
|
pos = pointed_thing.above
|
||||||
|
node = minetest.get_node(pos)
|
||||||
|
pdef = minetest.registered_nodes[node.name]
|
||||||
|
if not pdef or not pdef.buildable_to then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local player_name = placer:get_player_name()
|
||||||
|
-- Check sapling position for protection
|
||||||
|
if minetest.is_protected(pos, player_name) then
|
||||||
|
minetest.record_protection_violation(pos, player_name)
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
-- Check tree volume for protection
|
||||||
|
if not default.intersects_protection(
|
||||||
|
vector.add(pos, minp_relative),
|
||||||
|
vector.add(pos, maxp_relative),
|
||||||
|
player_name,
|
||||||
|
interval) then
|
||||||
|
minetest.set_node(pos, {name = sapling_name})
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
minetest.record_protection_violation(pos, player_name)
|
||||||
|
-- Print extra information to explain
|
||||||
|
minetest.chat_send_player(player_name, "Tree will intersect protection")
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- From BFD:
|
-- From BFD:
|
||||||
|
|
||||||
minetest.register_node("default:mg_cherry_sapling", {
|
minetest.register_node("default:mg_cherry_sapling", {
|
||||||
|
Loading…
Reference in New Issue
Block a user