mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-07-04 13:47:12 -04:00
Merge 23415c7e16
into 6ed522b5fc
This commit is contained in:
commit
c9d755b405
3 changed files with 157 additions and 198 deletions
|
@ -835,3 +835,17 @@ function default.can_interact_with_node(player, pos)
|
|||
|
||||
return false
|
||||
end
|
||||
|
||||
function default.do_with_area(p1, p2, func)
|
||||
local vm = VoxelManip()
|
||||
local minp, maxp = vm:read_from_map(p1, p2)
|
||||
local va = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
local data = vm:get_data()
|
||||
func(va, data)
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
vm:update_liquids()
|
||||
if vm.close ~= nil then
|
||||
vm:close()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -115,26 +115,13 @@ function default.grow_tree(pos, is_apple_tree, bad)
|
|||
error("Deprecated use of default.grow_tree")
|
||||
end
|
||||
|
||||
local x, y, z = pos.x, pos.y, pos.z
|
||||
local height = random(4, 5)
|
||||
local c_tree = minetest.get_content_id("default:tree")
|
||||
local c_leaves = minetest.get_content_id("default:leaves")
|
||||
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map(
|
||||
{x = x - 2, y = y, z = z - 2},
|
||||
{x = x + 2, y = y + height + 1, z = z + 2}
|
||||
)
|
||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
local data = vm:get_data()
|
||||
|
||||
default.do_with_area(pos:offset(-2, 0, -2), pos:offset(2, height + 1, 2), function(a, data)
|
||||
add_trunk_and_leaves(data, a, pos, c_tree, c_leaves, height, 2, 8, is_apple_tree)
|
||||
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
if vm.close ~= nil then
|
||||
vm:close()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Jungle tree
|
||||
|
@ -156,14 +143,7 @@ function default.grow_jungle_tree(pos, bad)
|
|||
local c_jungletree = minetest.get_content_id("default:jungletree")
|
||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
||||
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map(
|
||||
{x = x - 3, y = y - 1, z = z - 3},
|
||||
{x = x + 3, y = y + height + 1, z = z + 3}
|
||||
)
|
||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
local data = vm:get_data()
|
||||
|
||||
default.do_with_area(pos:offset(-3, -1, -3), pos:offset(3, height + 1, 3), function(a, data)
|
||||
add_trunk_and_leaves(data, a, pos, c_jungletree, c_jungleleaves,
|
||||
height, 3, 30, false)
|
||||
|
||||
|
@ -183,12 +163,7 @@ function default.grow_jungle_tree(pos, bad)
|
|||
vi_2 = vi_2 + 1
|
||||
end
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
if vm.close ~= nil then
|
||||
vm:close()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
@ -218,14 +193,7 @@ function default.grow_pine_tree(pos, snow)
|
|||
local c_pine_needles = minetest.get_content_id("default:pine_needles")
|
||||
local c_snow = minetest.get_content_id("default:snow")
|
||||
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local minp, maxp = vm:read_from_map(
|
||||
{x = x - 3, y = y, z = z - 3},
|
||||
{x = x + 3, y = maxy + 3, z = z + 3}
|
||||
)
|
||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
local data = vm:get_data()
|
||||
|
||||
default.do_with_area(pos:offset(-3, 0, -3), vector.new(x + 3, maxy + 3, z + 3), function(a, data)
|
||||
-- Upper branches layer
|
||||
local dev = 3
|
||||
for yy = maxy - 1, maxy + 1 do
|
||||
|
@ -311,12 +279,7 @@ function default.grow_pine_tree(pos, snow)
|
|||
data[vi] = c_pine_tree
|
||||
end
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
if vm.close ~= nil then
|
||||
vm:close()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -294,12 +294,8 @@ end
|
|||
local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner, explode_center)
|
||||
pos = vector.round(pos)
|
||||
-- scan for adjacent TNT nodes first, and enlarge the explosion
|
||||
local vm1 = VoxelManip()
|
||||
local p1 = vector.subtract(pos, 2)
|
||||
local p2 = vector.add(pos, 2)
|
||||
local minp, maxp = vm1:read_from_map(p1, p2)
|
||||
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
local data = vm1:get_data()
|
||||
-- TODO given that we're looking at a fraction of a mapblock here,
|
||||
-- there is probably little reason to use VoxelManip.
|
||||
local count = 0
|
||||
local c_tnt
|
||||
local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning")
|
||||
|
@ -311,6 +307,8 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne
|
|||
else
|
||||
c_tnt = c_tnt_burning -- tnt is not registered if disabled
|
||||
end
|
||||
|
||||
default.do_with_area(pos:subtract(2), pos:add(2), function(a, data)
|
||||
-- make sure we still have explosion even when centre node isnt tnt related
|
||||
if explode_center then
|
||||
count = 1
|
||||
|
@ -329,30 +327,20 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
vm1:set_data(data)
|
||||
vm1:write_to_map()
|
||||
if vm1.close ~= nil then
|
||||
vm1:close()
|
||||
end
|
||||
end)
|
||||
|
||||
-- recalculate new radius
|
||||
radius = math.floor(radius * math.pow(count, 1/3))
|
||||
|
||||
-- perform the explosion
|
||||
local vm = VoxelManip()
|
||||
local pr = PseudoRandom(os.time())
|
||||
p1 = vector.subtract(pos, radius)
|
||||
p2 = vector.add(pos, radius)
|
||||
minp, maxp = vm:read_from_map(p1, p2)
|
||||
a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
||||
data = vm:get_data()
|
||||
|
||||
local drops = {}
|
||||
local on_blast_queue = {}
|
||||
local on_construct_queue = {}
|
||||
basic_flame_on_construct = minetest.registered_nodes["fire:basic_flame"].on_construct
|
||||
|
||||
local p1, p2 = pos:subtract(radius), pos:add(radius)
|
||||
default.do_with_area(p1, p2, function(a, data) -- luacheck: ignore
|
||||
-- Used to efficiently remove metadata of nodes that were destroyed.
|
||||
-- Metadata is probably sparse, so this may save us some work.
|
||||
local has_meta = {}
|
||||
|
@ -386,13 +374,7 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
vm:write_to_map()
|
||||
vm:update_liquids()
|
||||
if vm.close ~= nil then
|
||||
vm:close()
|
||||
end
|
||||
end)
|
||||
|
||||
-- call check_single_for_falling for everything within 1.5x blast radius
|
||||
for y = -radius * 1.5, radius * 1.5 do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue