Attempt to correct behavior of item_drop on multiple single drops

This commit is contained in:
James Stevenson 2016-01-26 03:21:40 -05:00
parent b88de4845f
commit bc4cdcabe4

View File

@ -66,10 +66,15 @@ end)
function minetest.handle_node_drops(pos, drops, digger) function minetest.handle_node_drops(pos, drops, digger)
local inv = digger:get_inventory() local inv = digger:get_inventory()
local hand = digger:get_wielded_item() local hand = digger:get_wielded_item()
local hand_name = hand:get_name() print("----")
local hand_count = hand:get_count() print(dump(drops))
local hand_max = hand:get_stack_max() print("----")
for _, item in ipairs(drops) do for _, item in ipairs(drops) do
local hand_name = hand:get_name()
local hand_count = hand:get_count()
local hand_max = hand:get_stack_max()
local count, name local count, name
if type(item) == "string" then if type(item) == "string" then
count = 1 count = 1
@ -78,39 +83,23 @@ function minetest.handle_node_drops(pos, drops, digger)
count = item:get_count() count = item:get_count()
name = item:get_name() name = item:get_name()
end end
if not hand_name then return end
if (hand_name == name and hand_count ~= hand_max) if not inv then
or hand_name == "" then return
if hand_name == "" then end
digger:set_wielded_item(name .. " " .. count)
elseif inv and hand_count ~= hand_max then if (hand_name == name and hand_count ~= hand_max) then
digger:set_wielded_item(name .. " " .. hand_count + count) digger:set_wielded_item(name .. " " .. hand_count + count) -- FIXME Will go beyond hand_max
else minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.25, max_hear_distance = 7})
for i = 1, count do -- TODO Since most nearby items are merged, add in bulk print("adding " .. name .. " " .. count .. " to wielded stack")
local obj = minetest.add_item(pos, name)
if obj ~= nil then elseif hand_name == "" then
obj:get_luaentity().collect = true digger:set_wielded_item(name .. " " .. count)
local x = math.random(1, 5) minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.25, max_hear_distance = 7})
if math.random(1, 2) == 1 then print("placing " .. name .. " " .. count .. " in empty hand")
x = -x
end
local z = math.random(1, 5)
if math.random(1, 2) == 1 then
z = -z
end
obj:setvelocity({x = 1 / x, y = obj:getvelocity().y, z = 1 / z})
-- FIXME this doesnt work for deactiveted objects
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
obj:remove()
end, obj)
end
end
end
end
else else
for i = 1, count do for i = 1, count do -- TODO Since most nearby items are merged, add in bulk
local obj = minetest.add_item(pos, name) local obj = minetest.add_item(pos, name)
if obj ~= nil then if obj ~= nil then
obj:get_luaentity().collect = true obj:get_luaentity().collect = true
@ -124,7 +113,7 @@ function minetest.handle_node_drops(pos, drops, digger)
end end
obj:setvelocity({x = 1 / x, y = obj:getvelocity().y, z = 1 / z}) obj:setvelocity({x = 1 / x, y = obj:getvelocity().y, z = 1 / z})
-- FIXME this doesnt work for deactiveted objects -- FIXME this doesnt work for deactivated objects
if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
obj:remove() obj:remove()
@ -132,10 +121,11 @@ function minetest.handle_node_drops(pos, drops, digger)
end end
end end
end end
print("dropping " .. name .. " " .. count)
end end
end end
end end
if minetest.setting_getbool("log_mods") then if minetest.setting_getbool("log_mods") then
minetest.log("action", "[item_drop] loaded.") minetest.log("action", "[item_drop] Loaded")
end end