2021-03-27 20:12:48 +01:00
|
|
|
local random = math.random
|
|
|
|
|
2021-05-29 16:12:33 +02:00
|
|
|
local ipairs = ipairs
|
|
|
|
|
2021-03-27 20:12:48 +01:00
|
|
|
mcl_death_drop = {}
|
|
|
|
|
|
|
|
mcl_death_drop.registered_dropped_lists = {}
|
|
|
|
|
|
|
|
function mcl_death_drop.register_dropped_list(inv, listname, drop)
|
2021-05-29 16:12:33 +02:00
|
|
|
table.insert(mcl_death_drop.registered_dropped_lists, {inv = inv, listname = listname, drop = drop})
|
2021-03-27 20:12:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
mcl_death_drop.register_dropped_list("PLAYER", "main", true)
|
|
|
|
mcl_death_drop.register_dropped_list("PLAYER", "craft", true)
|
|
|
|
mcl_death_drop.register_dropped_list("PLAYER", "armor", true)
|
|
|
|
|
2017-07-24 19:20:06 +02:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
2019-03-25 12:42:37 +01:00
|
|
|
local keep = minetest.settings:get_bool("mcl_keepInventory", false)
|
2017-07-24 19:20:06 +02:00
|
|
|
if keep == false then
|
|
|
|
-- Drop inventory, crafting grid and armor
|
2021-03-27 20:23:51 +01:00
|
|
|
local playerinv = player:get_inventory()
|
2018-05-25 13:45:41 +02:00
|
|
|
local pos = player:get_pos()
|
|
|
|
-- No item drop if in deep void
|
2021-04-15 23:41:34 +02:00
|
|
|
local _, void_deadly = mcl_worlds.is_in_void(pos)
|
2021-03-27 20:12:48 +01:00
|
|
|
|
|
|
|
for l=1,#mcl_death_drop.registered_dropped_lists do
|
|
|
|
local inv = mcl_death_drop.registered_dropped_lists[l].inv
|
2021-03-27 20:23:51 +01:00
|
|
|
if inv == "PLAYER" then
|
|
|
|
inv = playerinv
|
|
|
|
elseif type(inv) == "function" then
|
|
|
|
inv = inv(player)
|
|
|
|
end
|
2021-03-27 20:12:48 +01:00
|
|
|
local listname = mcl_death_drop.registered_dropped_lists[l].listname
|
|
|
|
local drop = mcl_death_drop.registered_dropped_lists[l].drop
|
2021-05-29 16:12:33 +02:00
|
|
|
if inv then
|
2017-07-24 19:20:06 +02:00
|
|
|
for i, stack in ipairs(inv:get_list(listname)) do
|
2021-03-27 20:12:48 +01:00
|
|
|
local x = random(0, 9)/3
|
|
|
|
local z = random(0, 9)/3
|
2017-07-24 19:20:06 +02:00
|
|
|
pos.x = pos.x + x
|
|
|
|
pos.z = pos.z + z
|
2020-11-02 13:38:17 +01:00
|
|
|
if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then
|
2019-02-11 18:55:48 +01:00
|
|
|
local def = minetest.registered_items[stack:get_name()]
|
|
|
|
if def and def.on_drop then
|
|
|
|
stack = def.on_drop(stack, player, pos)
|
|
|
|
end
|
2017-07-24 19:20:06 +02:00
|
|
|
minetest.add_item(pos, stack)
|
|
|
|
end
|
|
|
|
pos.x = pos.x - x
|
|
|
|
pos.z = pos.z - z
|
|
|
|
end
|
2019-02-11 18:55:48 +01:00
|
|
|
inv:set_list(listname, {})
|
2017-07-24 19:20:06 +02:00
|
|
|
end
|
|
|
|
end
|
2021-04-14 15:46:52 +02:00
|
|
|
mcl_armor.update(player)
|
2017-07-24 19:20:06 +02:00
|
|
|
end
|
|
|
|
end)
|