2020-03-31 00:04:08 +02:00
|
|
|
local PICKUP_TIMER = 0.75
|
|
|
|
|
2020-03-30 22:41:58 +02:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
2020-03-30 22:43:46 +02:00
|
|
|
if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then
|
|
|
|
local pos = player:get_pos()
|
2020-03-30 22:41:58 +02:00
|
|
|
pos.y = pos.y+0.5
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
2020-03-30 22:43:46 +02:00
|
|
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
2020-03-31 00:04:08 +02:00
|
|
|
local lua = object:get_luaentity()
|
|
|
|
if not object:is_player() and lua and lua.name == "__builtin:item" then
|
|
|
|
if lua.timer and lua.timer >= PICKUP_TIMER and inv and inv:room_for_item("main", ItemStack(lua.itemstring)) then
|
|
|
|
inv:add_item("main", ItemStack(lua.itemstring))
|
|
|
|
if lua.itemstring ~= "" then
|
2020-03-30 22:41:58 +02:00
|
|
|
minetest.sound_play("item_drop_pickup", {
|
|
|
|
to_player = player:get_player_name(),
|
|
|
|
gain = 0.4,
|
2020-04-11 16:30:05 +02:00
|
|
|
}, true)
|
2020-03-30 22:41:58 +02:00
|
|
|
end
|
|
|
|
object:get_luaentity().itemstring = ""
|
|
|
|
object:remove()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-30 22:43:46 +02:00
|
|
|
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
|
2020-03-30 22:41:58 +02:00
|
|
|
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
|
|
|
|
if object:get_luaentity().collect then
|
|
|
|
if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
|
|
|
|
local pos1 = pos
|
|
|
|
pos1.y = pos1.y+0.2
|
2020-03-30 22:43:46 +02:00
|
|
|
local pos2 = object:get_pos()
|
2020-03-30 22:41:58 +02:00
|
|
|
local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
|
|
|
|
vec.x = vec.x*3
|
|
|
|
vec.y = vec.y*3
|
|
|
|
vec.z = vec.z*3
|
2020-03-30 22:43:46 +02:00
|
|
|
object:set_velocity(vec)
|
2020-03-30 22:41:58 +02:00
|
|
|
object:get_luaentity().physical_state = false
|
|
|
|
object:get_luaentity().object:set_properties({
|
|
|
|
physical = false
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.after(1, function(args)
|
|
|
|
local lua = object:get_luaentity()
|
2020-03-31 00:04:08 +02:00
|
|
|
if object == nil or lua == nil or lua.itemstring == nil or lua.timer == nil or lua.timer < PICKUP_TIMER then
|
2020-03-30 22:41:58 +02:00
|
|
|
return
|
|
|
|
end
|
2020-03-31 00:04:08 +02:00
|
|
|
if inv:room_for_item("main", ItemStack(lua.itemstring)) then
|
|
|
|
inv:add_item("main", ItemStack(lua.itemstring))
|
|
|
|
if lua.itemstring ~= "" then
|
2020-03-30 22:41:58 +02:00
|
|
|
minetest.sound_play("item_drop_pickup", {
|
|
|
|
to_player = player:get_player_name(),
|
|
|
|
gain = 0.4,
|
2020-04-11 16:30:05 +02:00
|
|
|
}, true)
|
2020-03-30 22:41:58 +02:00
|
|
|
end
|
|
|
|
object:get_luaentity().itemstring = ""
|
|
|
|
object:remove()
|
|
|
|
else
|
2020-03-30 22:43:46 +02:00
|
|
|
object:set_velocity({x=0,y=0,z=0})
|
2020-03-30 22:41:58 +02:00
|
|
|
object:get_luaentity().physical_state = true
|
|
|
|
object:get_luaentity().object:set_properties({
|
|
|
|
physical = true
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end, {player, object})
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2020-03-30 22:43:46 +02:00
|
|
|
if minetest.settings:get("log_mods") then
|
2020-03-30 23:15:58 +02:00
|
|
|
minetest.log("verbose", "item_drop loaded")
|
2020-03-30 22:41:58 +02:00
|
|
|
end
|