mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-04-01 10:10:36 +02:00
[item_drop] Optimize a bit; reduce ticking rate to 0.2s
This commit is contained in:
parent
1e6b0d0305
commit
54b20364fd
@ -26,63 +26,65 @@ minetest.register_globalstep(function(dtime)
|
|||||||
pos.y = pos.y + 0.9
|
pos.y = pos.y + 0.9
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
for _,object in ipairs(minetest.get_objects_inside_radius(pos, scan_range)) do
|
if inv then
|
||||||
local luaEnt = object:get_luaentity()
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, scan_range)) do
|
||||||
if not object:is_player() and luaEnt and luaEnt.name == "__builtin:item" then
|
local luaEnt = object:get_luaentity()
|
||||||
local ticky = luaEnt.item_drop_min_tstamp
|
if and luaEnt and luaEnt.name == "__builtin:item" then
|
||||||
if ticky then
|
local ticky = luaEnt.item_drop_min_tstamp
|
||||||
if tstamp >= ticky then
|
if ticky then
|
||||||
luaEnt.item_drop_min_tstamp = nil
|
if tstamp >= ticky then
|
||||||
end
|
luaEnt.item_drop_min_tstamp = nil
|
||||||
elseif not luaEnt.item_drop_nopickup then
|
end
|
||||||
-- Point-line distance computation, heavily simplified since the wanted line,
|
elseif not luaEnt.item_drop_nopickup then
|
||||||
-- being the player, is completely upright (no variation on X or Z)
|
-- Point-line distance computation, heavily simplified since the wanted line,
|
||||||
local pos2 = object:getpos()
|
-- being the player, is completely upright (no variation on X or Z)
|
||||||
-- No sqrt, avoid useless computation
|
local pos2 = object:getpos()
|
||||||
-- (just take the radius, compare it to the square of what you want)
|
-- No sqrt, avoid useless computation
|
||||||
-- Pos order doesn't really matter, we're squaring the result
|
-- (just take the radius, compare it to the square of what you want)
|
||||||
-- (but don't change it, we use the cached values afterwards)
|
-- Pos order doesn't really matter, we're squaring the result
|
||||||
local dX = pos.x-pos2.x
|
-- (but don't change it, we use the cached values afterwards)
|
||||||
local dZ = pos.z-pos2.z
|
local dX = pos.x-pos2.x
|
||||||
local playerDistance = dX*dX+dZ*dZ
|
local dZ = pos.z-pos2.z
|
||||||
if playerDistance <= pickup_range_squared then
|
local playerDistance = dX*dX+dZ*dZ
|
||||||
local itemStack = ItemStack(luaEnt.itemstring)
|
if playerDistance <= pickup_range_squared then
|
||||||
if inv and inv:room_for_item("main", itemStack) then
|
local itemStack = ItemStack(luaEnt.itemstring)
|
||||||
local pos1 = pos
|
if inv:room_for_item("main", itemStack) then
|
||||||
pos1.y = pos1.y-player_half_height+0.5
|
local pos1 = pos
|
||||||
local vec = {x=dX, y=pos1.y-pos2.y, z=dZ}
|
pos1.y = pos1.y-player_half_height+0.5
|
||||||
vec.x = vec.x*pickup_inv_duration
|
local vec = {x=dX, y=pos1.y-pos2.y, z=dZ}
|
||||||
vec.y = vec.y*pickup_inv_duration
|
vec.x = vec.x*pickup_inv_duration
|
||||||
vec.z = vec.z*pickup_inv_duration
|
vec.y = vec.y*pickup_inv_duration
|
||||||
object:setvelocity(vec)
|
vec.z = vec.z*pickup_inv_duration
|
||||||
luaEnt.physical_state = false
|
object:setvelocity(vec)
|
||||||
luaEnt.object:set_properties({
|
luaEnt.physical_state = false
|
||||||
physical = false
|
luaEnt.object:set_properties({
|
||||||
})
|
physical = false
|
||||||
-- Mark the object as already picking up
|
})
|
||||||
luaEnt.item_drop_nopickup = true
|
-- Mark the object as already picking up
|
||||||
|
luaEnt.item_drop_nopickup = true
|
||||||
|
|
||||||
minetest.after(pickup_duration, function(args)
|
minetest.after(pickup_duration, function(args)
|
||||||
local lua = luaEnt
|
local lua = luaEnt
|
||||||
if object == nil or lua == nil or lua.itemstring == nil then
|
if object == nil or lua == nil or lua.itemstring == nil then
|
||||||
return
|
return
|
||||||
end
|
|
||||||
if inv:room_for_item("main", itemStack) then
|
|
||||||
inv:add_item("main", itemStack)
|
|
||||||
if luaEnt.itemstring ~= "" then
|
|
||||||
minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.3, max_hear_distance = 8})
|
|
||||||
end
|
end
|
||||||
luaEnt.itemstring = ""
|
if inv:room_for_item("main", itemStack) then
|
||||||
object:remove()
|
inv:add_item("main", itemStack)
|
||||||
else
|
if luaEnt.itemstring ~= "" then
|
||||||
object:setvelocity({x = 0,y = 0,z = 0})
|
minetest.sound_play("item_drop_pickup", {pos = pos, gain = 0.3, max_hear_distance = 8})
|
||||||
luaEnt.physical_state = true
|
end
|
||||||
luaEnt.object:set_properties({
|
luaEnt.itemstring = ""
|
||||||
physical = true
|
object:remove()
|
||||||
})
|
else
|
||||||
luaEnt.item_drop_nopickup = nil
|
object:setvelocity({x = 0,y = 0,z = 0})
|
||||||
end
|
luaEnt.physical_state = true
|
||||||
end, {player, object})
|
luaEnt.object:set_properties({
|
||||||
|
physical = true
|
||||||
|
})
|
||||||
|
luaEnt.item_drop_nopickup = nil
|
||||||
|
end
|
||||||
|
end, {player, object})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user