Add code for zero velocity mode

This commit is contained in:
Hybrid Dog 2017-09-07 21:13:10 +02:00
parent 69a68cb247
commit bab3c733fa

@ -3,6 +3,7 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
minetest.settings:get("item_drop.pickup_sound_gain")) or 0.4
local pickup_radius = tonumber(
minetest.settings:get("item_drop.pickup_radius")) or 0.75
local inner_radius = 1
local pickup_age = tonumber(
minetest.settings:get("item_drop.pickup_age")) or 0.5
local key_triggered = minetest.settings:get_bool(
@ -13,8 +14,28 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
end
local damage_enabled = minetest.settings:get_bool("enable_damage")
-- gets the object's luaentity if it can be collected
local function opt_get_ent(object)
-- TODO add proper magnet range settings
local zero_velocity_mode = pickup_age == -1
and pickup_radius <= inner_radius
-- opt_get_ent gets the object's luaentity if it can be collected
local opt_get_ent, afterflight
if zero_velocity_mode then
function opt_get_ent(object)
if object:is_player()
or not vector.equals(object:getvelocity(), {x=0, y=0, z=0}) then
return
end
local ent = object:get_luaentity()
if not ent
or ent.name ~= "__builtin:item"
or ent.itemstring == "" then
return
end
return ent
end
else
function opt_get_ent(object)
if object:is_player() then
return
end
@ -29,7 +50,7 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
end
-- take item or reset velocity after flying a second
local function afterflight(object, inv, player)
function afterflight(object, inv, player)
local ent = opt_get_ent(object)
if not ent then
return
@ -54,6 +75,7 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
})
end
end
end
local function pickupfunc(player)
local keys_pressed = not key_triggered
@ -98,7 +120,7 @@ if minetest.settings:get_bool("item_drop.enable_item_pickup") ~= false then
if inv:room_for_item("main", ItemStack(ent.itemstring)) then
local pos2 = object:getpos()
local distance = vector.distance(pos, pos2)
if distance <= 1 then
if distance <= inner_radius then
inv:add_item("main", ItemStack(
ent.itemstring))
minetest.sound_play("item_drop_pickup", {