Drops mod optimization
parent
8d23c2530e
commit
6c594aa26a
|
@ -8,32 +8,33 @@ local function collect_items(player)
|
|||
if not minetest.is_valid_pos(pos) then
|
||||
return
|
||||
end
|
||||
local col_pos = vector.add(pos, {x=0, y=player_collect_height, z=0})
|
||||
-- Detect
|
||||
local col_pos = vector.add(pos, {x = 0, y = player_collect_height, z = 0})
|
||||
local objects = minetest.get_objects_inside_radius(col_pos, radius_magnet)
|
||||
for _,object in ipairs(objects) do
|
||||
local entity = object:get_luaentity()
|
||||
if entity and not object:is_player() and
|
||||
entity.name == "__builtin:item" and entity.age > age then
|
||||
if entity.collectioner == true and entity.age > entity.age_stamp then
|
||||
local inv = player:get_inventory()
|
||||
local item = ItemStack(entity.itemstring)
|
||||
--collect
|
||||
if item:get_name() ~= "" and inv and
|
||||
inv:room_for_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
pos = pos,
|
||||
max_hear_distance = 15,
|
||||
gain = 0.1,
|
||||
})
|
||||
entity.itemstring = ""
|
||||
object:remove()
|
||||
end
|
||||
else
|
||||
--magnet, moveto for extreme speed boost
|
||||
object:moveto(col_pos)
|
||||
local item = ItemStack(entity.itemstring)
|
||||
local inv = player:get_inventory()
|
||||
if item:get_name() ~= "" and inv and
|
||||
inv:room_for_item("main", item) then
|
||||
-- Magnet
|
||||
object:move_to(col_pos)
|
||||
entity.collectioner = true
|
||||
entity.age_stamp = entity.age
|
||||
-- Collect
|
||||
if entity.collectioner == true then
|
||||
minetest.after(0.01, function()
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
pos = pos,
|
||||
max_hear_distance = 10,
|
||||
gain = 0.25,
|
||||
})
|
||||
inv:add_item("main", item)
|
||||
entity.itemstring = ""
|
||||
object:remove()
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,7 +72,7 @@ local function get_next_player()
|
|||
return name or get_next_player()
|
||||
end
|
||||
|
||||
--Item collection
|
||||
-- Item collection
|
||||
minetest.register_globalstep(function()
|
||||
-- only deal with * player count on each server step
|
||||
for i = 1, players_per_step do
|
||||
|
@ -79,7 +80,6 @@ minetest.register_globalstep(function()
|
|||
if name then
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if player and player:is_player() and player:get_hp() > 0 then
|
||||
--radial detection
|
||||
collect_items(player)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue