2017-09-11 14:09:24 +02:00
|
|
|
local load_time_start = minetest.get_us_time()
|
|
|
|
|
2019-01-05 13:54:12 +01:00
|
|
|
-- Functions which can be overridden by mods
|
|
|
|
item_drop = {
|
|
|
|
-- This function is executed before picking up an item or making it fly to
|
|
|
|
-- the player. If it does not return true, the item is ignored.
|
|
|
|
-- It is also executed before collecting the item after it flew to
|
|
|
|
-- the player and did not reach him/her for magnet_time seconds.
|
|
|
|
can_pickup = function(entity, player)
|
2019-02-05 19:29:40 +01:00
|
|
|
if entity.item_drop_picked then
|
|
|
|
-- Ignore items where picking has already failed
|
|
|
|
return false
|
|
|
|
end
|
2019-01-05 13:54:12 +01:00
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
-- before_collect and after_collect are executed before and after an item
|
|
|
|
-- is collected by a player
|
|
|
|
before_collect = function(entity, pos, player)
|
|
|
|
end,
|
|
|
|
after_collect = function(entity, pos, player)
|
2019-02-05 19:29:40 +01:00
|
|
|
entity.item_drop_picked = true
|
2019-01-05 13:54:12 +01:00
|
|
|
end,
|
|
|
|
}
|
2017-09-11 14:09:24 +02:00
|
|
|
|
2019-05-29 20:44:40 +02:00
|
|
|
local function legacy_setting_getbool(name_new, name_old, default)
|
|
|
|
local v = minetest.settings:get_bool(name_new)
|
|
|
|
if v == nil then
|
|
|
|
v = minetest.settings:get_bool(name_new)
|
|
|
|
end
|
|
|
|
if default then
|
|
|
|
return v ~= false
|
|
|
|
end
|
|
|
|
return v
|
|
|
|
end
|
|
|
|
|
|
|
|
local function legacy_setting_getnumber(name_new, name_old, default)
|
|
|
|
return tonumber(minetest.settings:get(name_new))
|
|
|
|
or tonumber(minetest.settings:get(name_old))
|
|
|
|
or default
|
|
|
|
end
|
|
|
|
|
|
|
|
if legacy_setting_getbool("item_drop.enable_item_pickup",
|
|
|
|
"enable_item_pickup", true) then
|
|
|
|
local pickup_gain = legacy_setting_getnumber("item_drop.pickup_sound_gain",
|
|
|
|
"item_pickup_gain", 0.2)
|
2018-06-18 10:18:06 +02:00
|
|
|
local pickup_particle =
|
2019-05-29 20:44:40 +02:00
|
|
|
minetest.settings:get_bool("item_drop.pickup_particle", true)
|
|
|
|
local pickup_radius = legacy_setting_getnumber("item_drop.pickup_radius",
|
|
|
|
"item_pickup_radius", 0.75)
|
2017-09-08 20:25:16 +02:00
|
|
|
local magnet_radius = tonumber(
|
|
|
|
minetest.settings:get("item_drop.magnet_radius")) or -1
|
2017-09-08 20:42:28 +02:00
|
|
|
local magnet_time = tonumber(
|
|
|
|
minetest.settings:get("item_drop.magnet_time")) or 5.0
|
2017-09-07 20:39:49 +02:00
|
|
|
local pickup_age = tonumber(
|
|
|
|
minetest.settings:get("item_drop.pickup_age")) or 0.5
|
2019-05-29 20:44:40 +02:00
|
|
|
local key_triggered = legacy_setting_getbool("item_drop.enable_pickup_key",
|
|
|
|
"enable_item_pickup_key", true)
|
2017-09-08 20:36:36 +02:00
|
|
|
local key_invert = minetest.settings:get_bool(
|
2019-06-04 16:44:46 +02:00
|
|
|
"item_drop.pickup_keyinvert") ~= false
|
2017-09-06 15:51:34 +02:00
|
|
|
local keytype
|
|
|
|
if key_triggered then
|
2018-06-17 09:27:43 +02:00
|
|
|
keytype = minetest.settings:get("item_drop.pickup_keytype") or
|
|
|
|
minetest.settings:get("item_pickup_keytype") or "Use"
|
2017-09-16 12:57:21 +02:00
|
|
|
-- disable pickup age if picking is explicitly enabled by the player
|
|
|
|
if not key_invert then
|
|
|
|
pickup_age = math.min(pickup_age, 0)
|
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|
2019-02-12 01:12:59 +01:00
|
|
|
local mouse_pickup = minetest.settings:get_bool(
|
|
|
|
"item_drop.mouse_pickup") ~= false
|
|
|
|
if not mouse_pickup then
|
|
|
|
minetest.registered_entities["__builtin:item"].pointable = false
|
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2017-09-08 20:25:16 +02:00
|
|
|
local magnet_mode = magnet_radius > pickup_radius
|
2017-09-07 21:13:10 +02:00
|
|
|
local zero_velocity_mode = pickup_age == -1
|
2017-09-08 20:25:16 +02:00
|
|
|
if magnet_mode
|
|
|
|
and zero_velocity_mode then
|
|
|
|
error"zero velocity mode can't be used together with magnet mode"
|
|
|
|
end
|
2017-09-07 21:13:10 +02:00
|
|
|
|
2018-08-06 13:21:54 +02:00
|
|
|
-- tells whether an inventorycube should be shown as pickup_particle or not
|
|
|
|
-- for known drawtypes
|
|
|
|
local inventorycube_drawtypes = {
|
|
|
|
normal = true,
|
|
|
|
allfaces = true,
|
|
|
|
allfaces_optional = true,
|
|
|
|
glasslike = true,
|
|
|
|
glasslike_framed = true,
|
|
|
|
glasslike_framed_optional = true,
|
|
|
|
liquid = true,
|
|
|
|
flowingliquid = true,
|
|
|
|
}
|
|
|
|
|
2022-10-06 18:36:50 +02:00
|
|
|
-- Get an image string from a tile definition
|
|
|
|
local function tile_to_image(tile, fallback_image)
|
|
|
|
if not tile then
|
|
|
|
return fallback_image
|
|
|
|
end
|
|
|
|
local tile_type = type(tile)
|
|
|
|
if tile_type == "string" then
|
|
|
|
return tile
|
|
|
|
end
|
|
|
|
assert(tile_type == "table", "Tile definition is not a string or table")
|
|
|
|
local image = tile.name or tile.image
|
|
|
|
assert(image, "Tile definition has no image file specified")
|
|
|
|
if tile.color then
|
|
|
|
local colorstr = minetest.colorspec_to_colorstring(tile.color)
|
|
|
|
if colorstr then
|
|
|
|
return image .. "^[multiply:" .. colorstr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return image
|
|
|
|
end
|
|
|
|
|
2017-09-07 21:19:33 +02:00
|
|
|
-- adds the item to the inventory and removes the object
|
2017-09-11 14:44:31 +02:00
|
|
|
local function collect_item(ent, pos, player)
|
2019-01-05 13:54:12 +01:00
|
|
|
item_drop.before_collect(ent, pos, player)
|
2017-09-07 21:19:33 +02:00
|
|
|
minetest.sound_play("item_drop_pickup", {
|
|
|
|
pos = pos,
|
|
|
|
gain = pickup_gain,
|
2021-09-02 23:42:56 +02:00
|
|
|
}, true)
|
2018-06-18 10:18:06 +02:00
|
|
|
if pickup_particle then
|
2018-08-06 13:21:54 +02:00
|
|
|
local item = minetest.registered_nodes[
|
|
|
|
ent.itemstring:gsub("(.*)%s.*$", "%1")]
|
2020-05-25 20:42:09 +02:00
|
|
|
local image
|
2018-08-06 13:21:54 +02:00
|
|
|
if item and item.tiles and item.tiles[1] then
|
|
|
|
if inventorycube_drawtypes[item.drawtype] then
|
|
|
|
local tiles = item.tiles
|
2022-10-06 18:36:50 +02:00
|
|
|
-- color in the tile definition is handled by tile_to_image.
|
|
|
|
-- color in the node definition is not yet supported here.
|
|
|
|
local top = tile_to_image(tiles[1])
|
|
|
|
local left = tile_to_image(tiles[3], top)
|
|
|
|
local right = tile_to_image(tiles[5], left)
|
2018-08-06 13:21:54 +02:00
|
|
|
image = minetest.inventorycube(top, left, right)
|
|
|
|
else
|
|
|
|
image = item.inventory_image or item.tiles[1]
|
2018-06-18 10:18:06 +02:00
|
|
|
end
|
|
|
|
minetest.add_particle({
|
|
|
|
pos = {x = pos.x, y = pos.y + 1.5, z = pos.z},
|
|
|
|
velocity = {x = 0, y = 1, z = 0},
|
|
|
|
acceleration = {x = 0, y = -4, z = 0},
|
|
|
|
expirationtime = 0.2,
|
|
|
|
size = 3,--math.random() + 0.5,
|
|
|
|
vertical = false,
|
|
|
|
texture = image,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2017-09-11 14:44:31 +02:00
|
|
|
ent:on_punch(player)
|
2019-01-05 13:54:12 +01:00
|
|
|
item_drop.after_collect(ent, pos, player)
|
2017-09-07 21:19:33 +02:00
|
|
|
end
|
|
|
|
|
2017-09-07 21:13:10 +02:00
|
|
|
-- opt_get_ent gets the object's luaentity if it can be collected
|
2017-09-08 20:25:16 +02:00
|
|
|
local opt_get_ent
|
2017-09-07 21:13:10 +02:00
|
|
|
if zero_velocity_mode then
|
|
|
|
function opt_get_ent(object)
|
|
|
|
if object:is_player()
|
2019-06-15 00:47:21 +02:00
|
|
|
or not vector.equals(object:get_velocity(), {x=0, y=0, z=0}) then
|
2017-09-07 21:13:10 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local ent = object:get_luaentity()
|
|
|
|
if not ent
|
|
|
|
or ent.name ~= "__builtin:item"
|
|
|
|
or ent.itemstring == "" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return ent
|
2017-09-07 20:39:49 +02:00
|
|
|
end
|
2017-09-07 21:13:10 +02:00
|
|
|
else
|
|
|
|
function opt_get_ent(object)
|
|
|
|
if object:is_player() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local ent = object:get_luaentity()
|
|
|
|
if not ent
|
|
|
|
or ent.name ~= "__builtin:item"
|
|
|
|
or (ent.dropped_by and ent.age < pickup_age)
|
|
|
|
or ent.itemstring == "" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return ent
|
2017-09-07 20:39:49 +02:00
|
|
|
end
|
2017-09-08 20:25:16 +02:00
|
|
|
end
|
2017-09-07 20:39:49 +02:00
|
|
|
|
2017-09-08 20:25:16 +02:00
|
|
|
local afterflight
|
|
|
|
if magnet_mode then
|
2017-09-07 21:13:10 +02:00
|
|
|
-- take item or reset velocity after flying a second
|
2017-09-11 14:44:31 +02:00
|
|
|
function afterflight(object, inv, player)
|
|
|
|
-- TODO: test what happens if player left the game
|
2017-09-07 21:13:10 +02:00
|
|
|
local ent = opt_get_ent(object)
|
|
|
|
if not ent then
|
|
|
|
return
|
|
|
|
end
|
2017-09-07 21:19:33 +02:00
|
|
|
local item = ItemStack(ent.itemstring)
|
2017-09-07 21:13:10 +02:00
|
|
|
if inv
|
2019-01-05 13:54:12 +01:00
|
|
|
and inv:room_for_item("main", item)
|
2019-05-10 11:54:20 +02:00
|
|
|
and item_drop.can_pickup(ent, player) then
|
2017-09-11 14:44:31 +02:00
|
|
|
collect_item(ent, object:get_pos(), player)
|
2017-09-07 21:13:10 +02:00
|
|
|
else
|
2018-10-03 17:07:25 +02:00
|
|
|
-- the acceleration will be reset by the object's on_step
|
|
|
|
object:set_velocity({x=0,y=0,z=0})
|
|
|
|
ent.is_magnet_item = false
|
2017-09-07 21:13:10 +02:00
|
|
|
end
|
2017-09-07 20:57:02 +02:00
|
|
|
end
|
2018-10-03 17:07:25 +02:00
|
|
|
|
|
|
|
-- disable velocity and acceleration changes of items flying to players
|
|
|
|
minetest.after(0, function()
|
|
|
|
local ObjectRef
|
|
|
|
local blocked_methods = {"set_acceleration", "set_velocity",
|
|
|
|
"setacceleration", "setvelocity"}
|
|
|
|
local itemdef = minetest.registered_entities["__builtin:item"]
|
|
|
|
local old_on_step = itemdef.on_step
|
|
|
|
local function do_nothing() end
|
2020-05-08 11:54:31 +02:00
|
|
|
function itemdef.on_step(self, ...)
|
2018-10-03 17:07:25 +02:00
|
|
|
if not self.is_magnet_item then
|
2020-05-08 11:54:31 +02:00
|
|
|
return old_on_step(self, ...)
|
2018-10-03 17:07:25 +02:00
|
|
|
end
|
|
|
|
ObjectRef = ObjectRef or getmetatable(self.object)
|
|
|
|
local old_funcs = {}
|
|
|
|
for i = 1, #blocked_methods do
|
|
|
|
local method = blocked_methods[i]
|
|
|
|
old_funcs[method] = ObjectRef[method]
|
|
|
|
ObjectRef[method] = do_nothing
|
|
|
|
end
|
2020-05-08 11:54:31 +02:00
|
|
|
old_on_step(self, ...)
|
2018-10-03 17:07:25 +02:00
|
|
|
for i = 1, #blocked_methods do
|
|
|
|
local method = blocked_methods[i]
|
|
|
|
ObjectRef[method] = old_funcs[method]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2017-09-07 20:57:02 +02:00
|
|
|
end
|
|
|
|
|
2017-09-08 20:57:05 +02:00
|
|
|
-- set keytype to the key name if possible
|
|
|
|
if keytype == "Use" then
|
|
|
|
keytype = "aux1"
|
|
|
|
elseif keytype == "Sneak" then
|
|
|
|
keytype = "sneak"
|
|
|
|
elseif keytype == "LeftAndRight" then -- LeftAndRight combination
|
|
|
|
keytype = 0
|
|
|
|
elseif keytype == "SneakAndRMB" then -- SneakAndRMB combination
|
|
|
|
keytype = 1
|
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
|
|
|
|
|
2017-09-08 20:57:05 +02:00
|
|
|
-- tests if the player has the keys pressed to enable item picking
|
2017-09-16 13:18:20 +02:00
|
|
|
local function has_keys_pressed(player)
|
2017-09-08 20:57:05 +02:00
|
|
|
if not key_triggered then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local control = player:get_player_control()
|
|
|
|
local keys_pressed
|
|
|
|
if keytype == 0 then -- LeftAndRight combination
|
2017-09-07 21:00:55 +02:00
|
|
|
keys_pressed = control.left and control.right
|
2017-09-15 18:40:11 +02:00
|
|
|
elseif keytype == 1 then -- SneakAndRMB combination
|
2017-09-07 21:00:55 +02:00
|
|
|
keys_pressed = control.sneak and control.RMB
|
2017-09-08 20:57:05 +02:00
|
|
|
else
|
|
|
|
keys_pressed = control[keytype]
|
2017-09-07 21:00:55 +02:00
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2017-09-08 20:57:05 +02:00
|
|
|
return keys_pressed ~= key_invert
|
|
|
|
end
|
|
|
|
|
2020-05-17 21:12:57 +02:00
|
|
|
local function is_inside_map(pos)
|
|
|
|
local bound = 31000
|
|
|
|
return -bound < pos.x and pos.x < bound
|
|
|
|
and -bound < pos.y and pos.y < bound
|
|
|
|
and -bound < pos.z and pos.z < bound
|
|
|
|
end
|
|
|
|
|
2017-09-12 10:13:49 +02:00
|
|
|
-- called for each player to possibly collect an item, returns true if so
|
2017-09-08 20:57:05 +02:00
|
|
|
local function pickupfunc(player)
|
2017-09-16 13:18:20 +02:00
|
|
|
if not has_keys_pressed(player)
|
2017-09-11 14:08:01 +02:00
|
|
|
or not minetest.get_player_privs(player:get_player_name()).interact
|
2017-09-08 20:46:36 +02:00
|
|
|
or player:get_hp() <= 0 then
|
2017-09-07 21:00:55 +02:00
|
|
|
return
|
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2019-06-15 13:26:24 +02:00
|
|
|
local pos = player:get_pos()
|
2020-05-17 21:12:57 +02:00
|
|
|
if not is_inside_map(pos) then
|
|
|
|
-- get_objects_inside_radius crashes for too far positions
|
|
|
|
return
|
|
|
|
end
|
2017-09-07 21:00:55 +02:00
|
|
|
pos.y = pos.y+0.5
|
2020-04-15 20:21:48 +02:00
|
|
|
local inv = player:get_inventory()
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2017-09-07 21:00:55 +02:00
|
|
|
local objectlist = minetest.get_objects_inside_radius(pos,
|
2017-09-08 20:25:16 +02:00
|
|
|
magnet_mode and magnet_radius or pickup_radius)
|
2017-09-07 21:00:55 +02:00
|
|
|
for i = 1,#objectlist do
|
|
|
|
local object = objectlist[i]
|
|
|
|
local ent = opt_get_ent(object)
|
2019-01-05 13:54:12 +01:00
|
|
|
if ent
|
|
|
|
and item_drop.can_pickup(ent, player) then
|
2017-09-07 21:19:33 +02:00
|
|
|
local item = ItemStack(ent.itemstring)
|
|
|
|
if inv:room_for_item("main", item) then
|
2017-09-12 10:13:49 +02:00
|
|
|
local flying_item
|
|
|
|
local pos2
|
|
|
|
if magnet_mode then
|
2019-06-15 00:47:21 +02:00
|
|
|
pos2 = object:get_pos()
|
2017-09-12 10:13:49 +02:00
|
|
|
flying_item = vector.distance(pos, pos2) > pickup_radius
|
|
|
|
end
|
|
|
|
if not flying_item then
|
2019-01-05 13:54:12 +01:00
|
|
|
-- The item is near enough to pick it
|
2017-09-11 14:44:31 +02:00
|
|
|
collect_item(ent, pos, player)
|
2019-01-05 13:54:12 +01:00
|
|
|
-- Collect one item at a time to avoid the loud pop
|
2017-09-08 21:26:08 +02:00
|
|
|
return true
|
|
|
|
end
|
2019-01-05 13:54:12 +01:00
|
|
|
-- The item is not too far a way but near enough to be
|
|
|
|
-- magnetised, make it fly to the player
|
2018-10-03 17:07:25 +02:00
|
|
|
local vel = vector.multiply(vector.subtract(pos, pos2), 3)
|
2017-09-12 10:13:49 +02:00
|
|
|
vel.y = vel.y + 0.6
|
2018-10-03 17:07:25 +02:00
|
|
|
object:set_velocity(vel)
|
|
|
|
if not ent.is_magnet_item then
|
|
|
|
ent.object:set_acceleration({x=0, y=0, z=0})
|
|
|
|
ent.is_magnet_item = true
|
2017-09-12 10:13:49 +02:00
|
|
|
|
|
|
|
minetest.after(magnet_time, afterflight,
|
|
|
|
object, inv, player)
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function pickup_step()
|
2017-09-08 21:26:08 +02:00
|
|
|
local got_item
|
2017-09-07 21:00:55 +02:00
|
|
|
local players = minetest.get_connected_players()
|
|
|
|
for i = 1,#players do
|
2017-09-08 21:26:08 +02:00
|
|
|
got_item = got_item or pickupfunc(players[i])
|
|
|
|
end
|
|
|
|
-- lower step if takeable item(s) were found
|
|
|
|
local time
|
|
|
|
if got_item then
|
|
|
|
time = 0.02
|
|
|
|
else
|
|
|
|
time = 0.2
|
2017-09-07 21:00:55 +02:00
|
|
|
end
|
2017-09-08 21:26:08 +02:00
|
|
|
minetest.after(time, pickup_step)
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|
|
|
|
minetest.after(3.0, pickup_step)
|
2017-06-26 15:57:23 +02:00
|
|
|
end
|
2012-09-01 03:49:44 +02:00
|
|
|
|
2019-05-29 20:44:40 +02:00
|
|
|
if legacy_setting_getbool("item_drop.enable_item_drop", "enable_item_drop", true)
|
2017-09-11 14:35:55 +02:00
|
|
|
and not minetest.settings:get_bool("creative_mode") then
|
2019-07-01 15:37:04 +02:00
|
|
|
-- Workaround to test if an item metadata (ItemStackMetaRef) is empty
|
|
|
|
local function itemmeta_is_empty(meta)
|
|
|
|
local t = meta:to_table()
|
|
|
|
for k, v in pairs(t) do
|
|
|
|
if k ~= "fields" then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
assert(type(v) == "table")
|
|
|
|
if next(v) ~= nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Tests if the item has special information such as metadata
|
|
|
|
local function can_split_item(item)
|
|
|
|
return item:get_wear() == 0 and itemmeta_is_empty(item:get_meta())
|
|
|
|
end
|
|
|
|
|
|
|
|
local function spawn_items(pos, items_to_spawn)
|
|
|
|
for i = 1,#items_to_spawn do
|
|
|
|
local obj = minetest.add_item(pos, items_to_spawn[i])
|
|
|
|
if not obj then
|
|
|
|
error("Couldn't spawn item " .. name .. ", drops: "
|
|
|
|
.. dump(drops))
|
|
|
|
end
|
|
|
|
|
|
|
|
local vel = obj:get_velocity()
|
|
|
|
local x = math.random(-5, 4)
|
|
|
|
if x >= 0 then
|
|
|
|
x = x+1
|
|
|
|
end
|
|
|
|
vel.x = 1 / x
|
|
|
|
local z = math.random(-5, 4)
|
|
|
|
if z >= 0 then
|
|
|
|
z = z+1
|
|
|
|
end
|
|
|
|
vel.z = 1 / z
|
|
|
|
obj:set_velocity(vel)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 18:30:49 +02:00
|
|
|
local old_handle_node_drops = minetest.handle_node_drops
|
|
|
|
function minetest.handle_node_drops(pos, drops, player)
|
2020-09-27 19:15:57 +02:00
|
|
|
if not player or player.is_fake_player then
|
2019-09-04 18:30:49 +02:00
|
|
|
-- Node Breaker or similar machines should receive items in the
|
|
|
|
-- inventory
|
|
|
|
return old_handle_node_drops(pos, drops, player)
|
|
|
|
end
|
2017-09-11 14:22:17 +02:00
|
|
|
for i = 1,#drops do
|
|
|
|
local item = drops[i]
|
2017-09-06 15:51:34 +02:00
|
|
|
if type(item) == "string" then
|
2019-07-01 15:37:04 +02:00
|
|
|
-- The string is not necessarily only the item name,
|
|
|
|
-- so always convert it to ItemStack
|
|
|
|
item = ItemStack(item)
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|
2019-07-01 15:37:04 +02:00
|
|
|
local count = item:get_count()
|
|
|
|
local name = item:get_name()
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2019-02-01 17:55:12 +01:00
|
|
|
-- Sometimes nothing should be dropped
|
|
|
|
if name == ""
|
2019-05-16 11:36:15 +02:00
|
|
|
or not minetest.registered_items[name] then
|
2018-06-23 10:01:40 +02:00
|
|
|
count = 0
|
|
|
|
end
|
|
|
|
|
2019-07-01 15:37:04 +02:00
|
|
|
if count > 0 then
|
|
|
|
-- Split items if possible
|
|
|
|
local items_to_spawn = {item}
|
|
|
|
if can_split_item(item) then
|
|
|
|
for i = 1,count do
|
|
|
|
items_to_spawn[i] = name
|
|
|
|
end
|
2017-09-11 14:35:55 +02:00
|
|
|
end
|
2017-09-06 15:51:34 +02:00
|
|
|
|
2019-07-01 15:37:04 +02:00
|
|
|
spawn_items(pos, items_to_spawn)
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-10-07 19:44:16 +02:00
|
|
|
|
2020-06-16 22:54:09 +02:00
|
|
|
local function pickup_step()
|
|
|
|
local got_item
|
|
|
|
local players = minetest.get_connected_players()
|
|
|
|
for i = 1,#players do
|
|
|
|
got_item = got_item or pickupfunc(players[i])
|
|
|
|
end
|
|
|
|
-- lower step if takeable item(s) were found
|
|
|
|
local time
|
|
|
|
if got_item then
|
|
|
|
time = 0.02
|
|
|
|
else
|
|
|
|
time = 0.2
|
|
|
|
end
|
|
|
|
minetest.after(time, pickup_step)
|
|
|
|
end
|
|
|
|
minetest.after(3.0, pickup_step)
|
|
|
|
end
|
2017-09-11 14:09:24 +02:00
|
|
|
|
|
|
|
local time = (minetest.get_us_time() - load_time_start) / 1000000
|
|
|
|
local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
|
|
|
|
if time > 0.01 then
|
|
|
|
print(msg)
|
|
|
|
else
|
2018-12-26 00:05:48 +01:00
|
|
|
minetest.log("action", msg)
|
2017-09-06 15:51:34 +02:00
|
|
|
end
|