mirror of
https://github.com/minetest-mods/technic.git
synced 2024-12-26 02:40:29 +01:00
Make sure chainsaw drops appear above ground
A fix for https://github.com/minetest-technic/technic/issues/137 Chainsaw drops are forced to pop above ground. Also, as asl suggested, they must not end up too high on a ledge or a pillar. This also cleans up the code style of chainsaw.lua.
This commit is contained in:
parent
c394984ae5
commit
c636582707
@ -132,7 +132,6 @@ local produced = nil
|
||||
-- items sawed down so that we can drop them i an nice single stack
|
||||
local function chainsaw_handle_node_drops(pos, drops, digger)
|
||||
-- Add dropped items to list of collected nodes
|
||||
local _, dropped_item
|
||||
for _, dropped_item in ipairs(drops) do
|
||||
if produced[dropped_item] == nil then
|
||||
produced[dropped_item] = 1
|
||||
@ -204,6 +203,36 @@ 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 drop_pos = {}
|
||||
|
||||
for i = 0, 8 do
|
||||
-- Randomize position for a new drop
|
||||
drop_pos.x = pos.x + math.random(-3, 3)
|
||||
drop_pos.y = pos.y - 1
|
||||
drop_pos.z = pos.z + math.random(-3, 3)
|
||||
|
||||
-- Move the randomized position upwards until
|
||||
-- the node is air or unloaded.
|
||||
for y = drop_pos.y, drop_pos.y + 5 do
|
||||
drop_pos.y = y
|
||||
local node = minetest.get_node_or_nil(drop_pos)
|
||||
|
||||
if not node then
|
||||
-- If the node is not loaded yet simply drop
|
||||
-- the item at the original digging position.
|
||||
return pos
|
||||
elseif node.name == "air" then
|
||||
return drop_pos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Return the original position if this takes too long
|
||||
return pos
|
||||
end
|
||||
|
||||
-- Saw down trees entry point
|
||||
local function chainsaw_dig_it(pos, player,current_charge)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
@ -232,18 +261,10 @@ local function chainsaw_dig_it(pos, player,current_charge)
|
||||
for produced_item,number in pairs(produced) do
|
||||
--print("ADDING ITEM: " .. produced_item .. " " .. number)
|
||||
-- Drop stacks of 99 or less
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
p = get_drop_pos(pos)
|
||||
while number > 99 do
|
||||
minetest.env:add_item(p, produced_item .. " 99")
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
p = get_drop_pos(pos)
|
||||
number = number - 99
|
||||
end
|
||||
minetest.env:add_item(p, produced_item .. " " .. number)
|
||||
@ -287,4 +308,3 @@ minetest.register_craft({
|
||||
{'', '', 'default:copper_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user