2017-07-24 17:20:06 +00:00
|
|
|
minetest.register_on_dieplayer(function(player)
|
2019-03-25 11:42:37 +00:00
|
|
|
local keep = minetest.settings:get_bool("mcl_keepInventory", false)
|
2017-07-24 17:20:06 +00:00
|
|
|
if keep == false then
|
|
|
|
-- Drop inventory, crafting grid and armor
|
|
|
|
local inv = player:get_inventory()
|
2018-05-25 11:45:41 +00:00
|
|
|
local pos = player:get_pos()
|
2017-07-24 17:20:06 +00:00
|
|
|
local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
2018-05-25 11:45:41 +00:00
|
|
|
-- No item drop if in deep void
|
|
|
|
local void, void_deadly = mcl_worlds.is_in_void(pos)
|
2017-07-24 17:20:06 +00:00
|
|
|
local lists = {
|
|
|
|
{ inv = inv, listname = "main", drop = true },
|
|
|
|
{ inv = inv, listname = "craft", drop = true },
|
|
|
|
{ inv = player_armor_inv, listname = "armor", drop = true },
|
|
|
|
{ inv = armor_armor_inv, listname = "armor", drop = false },
|
|
|
|
}
|
|
|
|
for l=1,#lists do
|
|
|
|
local inv = lists[l].inv
|
|
|
|
local listname = lists[l].listname
|
|
|
|
local drop = lists[l].drop
|
|
|
|
if inv ~= nil then
|
|
|
|
for i, stack in ipairs(inv:get_list(listname)) do
|
|
|
|
local x = math.random(0, 9)/3
|
|
|
|
local z = math.random(0, 9)/3
|
|
|
|
pos.x = pos.x + x
|
|
|
|
pos.z = pos.z + z
|
2018-05-25 11:45:41 +00:00
|
|
|
if not void_deadly and drop then
|
2019-02-11 17:55:48 +00: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 17:20:06 +00:00
|
|
|
minetest.add_item(pos, stack)
|
|
|
|
end
|
|
|
|
pos.x = pos.x - x
|
|
|
|
pos.z = pos.z - z
|
|
|
|
end
|
2019-02-11 17:55:48 +00:00
|
|
|
inv:set_list(listname, {})
|
2017-07-24 17:20:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
armor:set_player_armor(player)
|
|
|
|
armor:update_inventory(player)
|
|
|
|
end
|
|
|
|
end)
|