2020-03-14 17:50:24 +00:00
|
|
|
dropondie = {}
|
|
|
|
|
|
|
|
local registered_drop_filters = {}
|
|
|
|
|
|
|
|
-- return true to drop, false to destroy
|
|
|
|
function dropondie.register_drop_filter(func, priority)
|
|
|
|
table.insert(registered_drop_filters,
|
|
|
|
priority or (#registered_drop_filters + 1),
|
|
|
|
func)
|
|
|
|
end
|
|
|
|
|
2019-03-19 16:54:43 +00:00
|
|
|
local blacklist_drop = {}
|
2020-03-14 17:50:24 +00:00
|
|
|
dropondie.register_drop_filter(function(player, itemname)
|
|
|
|
return table.indexof(blacklist_drop, itemname) == -1
|
|
|
|
end)
|
2015-07-16 17:44:01 +00:00
|
|
|
|
2020-03-14 17:50:24 +00:00
|
|
|
local function drop(player, pos, itemstack)
|
2015-07-16 17:44:01 +00:00
|
|
|
local it = itemstack:take_item(itemstack:get_count())
|
2015-12-08 01:20:36 +00:00
|
|
|
local sname = it:get_name()
|
|
|
|
|
2020-03-14 17:50:24 +00:00
|
|
|
for i=1, #registered_drop_filters do
|
|
|
|
if not registered_drop_filters[i](player, sname) then
|
|
|
|
return itemstack
|
2015-12-08 01:20:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-06 13:04:56 +00:00
|
|
|
local obj = minetest.add_item(pos, it)
|
2015-07-16 17:44:01 +00:00
|
|
|
|
|
|
|
if obj then
|
2019-10-18 05:52:18 +00:00
|
|
|
obj:set_velocity({ x = math.random(-1, 1), y = 5, z = math.random(-1, 1) })
|
2015-07-16 17:44:01 +00:00
|
|
|
|
2018-12-30 23:08:25 +00:00
|
|
|
local remi = minetest.settings:get("remove_items")
|
2015-12-07 23:00:32 +00:00
|
|
|
if minetest.is_yes(remi) then
|
|
|
|
obj:remove()
|
|
|
|
end
|
2015-07-16 17:44:01 +00:00
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2020-03-14 17:50:24 +00:00
|
|
|
local function drop_list(player, pos, inv, list)
|
2018-01-27 18:45:52 +00:00
|
|
|
for i = 1, inv:get_size(list) do
|
2020-03-14 17:50:24 +00:00
|
|
|
drop(player, pos, inv:get_stack(list, i))
|
2018-01-27 18:45:52 +00:00
|
|
|
inv:set_stack(list, i, nil)
|
2015-07-16 17:44:01 +00:00
|
|
|
end
|
2018-01-27 18:45:52 +00:00
|
|
|
end
|
2015-07-16 17:44:01 +00:00
|
|
|
|
2018-01-27 18:45:52 +00:00
|
|
|
local function drop_all(player)
|
2019-09-07 09:06:18 +00:00
|
|
|
local pos = player:get_pos()
|
2015-07-16 17:44:01 +00:00
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
|
2018-01-27 18:45:52 +00:00
|
|
|
local inv = player:get_inventory()
|
2020-03-13 21:58:42 +00:00
|
|
|
for _, item in pairs(give_initial_stuff.get_stuff(player)) do
|
2018-01-27 18:45:52 +00:00
|
|
|
inv:remove_item("main", ItemStack(item))
|
2015-07-16 17:44:01 +00:00
|
|
|
end
|
2020-03-14 17:50:24 +00:00
|
|
|
drop_list(player, pos, inv, "main")
|
|
|
|
drop_list(player, pos, inv, "craft")
|
2015-12-08 01:20:36 +00:00
|
|
|
end
|
2015-07-16 17:44:01 +00:00
|
|
|
|
2015-12-08 01:20:36 +00:00
|
|
|
minetest.register_on_dieplayer(drop_all)
|
|
|
|
minetest.register_on_leaveplayer(drop_all)
|