mirror of
https://github.com/minetest-mods/technic.git
synced 2025-07-06 18:20:37 +02:00
Added comments and made some small changes
In get_drop_pos(): improved comments, added variation to drop positions and made it handle unloaded blocks in a new way.
This commit is contained in:
@ -55,9 +55,9 @@ if( minetest.get_modpath("moretrees") ~= nil ) then
|
||||
if chainsaw_leaves then
|
||||
timber_nodenames["moretrees:apple_tree_leaves"] = true
|
||||
timber_nodenames["moretrees:oak_leaves"] = true
|
||||
timber_nodenames["moretrees:sequoia_leaves"] = true
|
||||
timber_nodenames["moretrees:fir_leaves"] = true
|
||||
timber_nodenames["moretrees:fir_leaves_bright"] = true
|
||||
timber_nodenames["moretrees:sequoia_leaves"] = true
|
||||
timber_nodenames["moretrees:birch_leaves"] = true
|
||||
timber_nodenames["moretrees:birch_leaves"] = true
|
||||
timber_nodenames["moretrees:palm_leaves"] = true
|
||||
@ -203,20 +203,39 @@ local function recursive_dig(pos, remaining_charge, player)
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Function to randomize positions for new node drops
|
||||
local function get_drop_pos(pos)
|
||||
local p, node
|
||||
local drop_pos, node
|
||||
|
||||
repeat
|
||||
p = {
|
||||
-- Randomize position for a new drop
|
||||
drop_pos = {
|
||||
x = pos.x + math.random(-3, 3),
|
||||
y = pos.y - 1,
|
||||
z = pos.z + math.random(-3, 3)
|
||||
}
|
||||
|
||||
-- Move the newly-randomized position upwards until there's
|
||||
-- no node in it or an unloaded block is found
|
||||
repeat
|
||||
p.y = p.y + 1
|
||||
node = minetest.get_node(p).name
|
||||
until node == "air" or node == "ignore" -- Make sure drops wont appear inside ground
|
||||
until p.y < pos.y + 5 -- Make sure the drops dont end up on a high ledge or column
|
||||
return p
|
||||
drop_pos.y = drop_pos.y + 1
|
||||
node = minetest.get_node(drop_pos).name
|
||||
|
||||
if node == "ignore" then
|
||||
-- On a rare chase where the block above the digging position is not
|
||||
-- loaded yet, simply drop the nodes at the original digging position
|
||||
return pos
|
||||
end
|
||||
until node == "air"
|
||||
|
||||
-- Make sure the drops will not end up too high on a tall ledge or a column
|
||||
until drop_pos.y < pos.y + 5
|
||||
|
||||
-- Add some variation to the previously integer-only position
|
||||
drop_pos.x = drop_pos.x + math.random() - .5
|
||||
drop_pos.z = drop_pos.z + math.random() - .5
|
||||
|
||||
return drop_pos
|
||||
end
|
||||
|
||||
-- Saw down trees entry point
|
||||
@ -294,4 +313,3 @@ minetest.register_craft({
|
||||
{'', '', 'default:copper_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user