mirror of
https://github.com/minetest/minetest_game.git
synced 2025-01-09 15:00:18 +01:00
fixes as per code review completed (4)
This commit is contained in:
parent
5141c96c01
commit
4b2228066f
@ -224,36 +224,22 @@ end
|
|||||||
|
|
||||||
bones.register_dead_player_inv_management(player_dies_transfer_inventory)
|
bones.register_dead_player_inv_management(player_dies_transfer_inventory)
|
||||||
|
|
||||||
minetest.register_on_dieplayer(function(player)
|
local function collect_all_items(player)
|
||||||
local player_pos = vector.round(player:get_pos())
|
local all_inventory = {}
|
||||||
local bones_mode = minetest.settings:get("bones_mode") or "bones"
|
|
||||||
if bones_mode ~= "bones" and bones_mode ~= "drop" and bones_mode ~= "keep" then
|
|
||||||
bones_mode = "bones"
|
|
||||||
end
|
|
||||||
local player_name = player:get_player_name()
|
|
||||||
local bones_inv = nil
|
|
||||||
local bones_pos = nil
|
|
||||||
local dropped = false
|
|
||||||
local bones_meta = nil
|
|
||||||
|
|
||||||
local bones_position_message = minetest.settings:get_bool("bones_position_message") == true
|
|
||||||
local pos_string = minetest.pos_to_string(player_pos)
|
|
||||||
|
|
||||||
-- return if keep inventory set or in creative mode
|
|
||||||
if bones_mode == "keep" or minetest.is_creative_enabled(player_name) then
|
|
||||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
|
||||||
". No bones placed")
|
|
||||||
if bones_position_message then
|
|
||||||
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, fun in ipairs(dead_player_callbacks) do
|
for _, fun in ipairs(dead_player_callbacks) do
|
||||||
local items = fun(player)
|
local items = fun(player)
|
||||||
for _, item in ipairs(items) do
|
-- https://www.programming-idioms.org/idiom/166/concatenate-two-lists/3812/lua
|
||||||
|
table.move(items, 1, #items, #all_inventory + 1, all_inventory)
|
||||||
|
end
|
||||||
|
return all_inventory
|
||||||
|
end
|
||||||
|
|
||||||
-- check if it's possible to place bones, if not find space near player
|
-- check if it's possible to place bones, if not find space near player
|
||||||
if bones_mode == "bones" and bones_pos == nil then
|
local function find_node_for_bones_on_player_death(player, player_pos)
|
||||||
|
local bones_pos = nil
|
||||||
|
local bones_inv = nil
|
||||||
|
local bones_meta = nil
|
||||||
|
local bones_mode = "bones"
|
||||||
bones_pos = player_pos
|
bones_pos = player_pos
|
||||||
local air
|
local air
|
||||||
if may_replace(bones_pos, player) then
|
if may_replace(bones_pos, player) then
|
||||||
@ -274,8 +260,12 @@ minetest.register_on_dieplayer(function(player)
|
|||||||
bones_mode = "drop"
|
bones_mode = "drop"
|
||||||
bones_pos = nil
|
bones_pos = nil
|
||||||
end
|
end
|
||||||
|
return bones_mode, bones_pos, bones_inv, bones_meta
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function dump_into(bones_mode, bones_inv, bones_pos, all_inventory)
|
||||||
|
local dropped = false
|
||||||
|
for _, item in ipairs(all_inventory) do
|
||||||
if bones_mode == "bones" and bones_inv:room_for_item("main", item) then
|
if bones_mode == "bones" and bones_inv:room_for_item("main", item) then
|
||||||
bones_inv:add_item("main", item)
|
bones_inv:add_item("main", item)
|
||||||
else
|
else
|
||||||
@ -283,8 +273,42 @@ minetest.register_on_dieplayer(function(player)
|
|||||||
dropped = true
|
dropped = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return dropped
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
local player_pos = vector.round(player:get_pos())
|
||||||
|
local bones_mode = minetest.settings:get("bones_mode") or "bones"
|
||||||
|
if bones_mode ~= "bones" and bones_mode ~= "drop" and bones_mode ~= "keep" then
|
||||||
|
bones_mode = "bones"
|
||||||
|
end
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
local bones_inv = nil
|
||||||
|
local bones_pos = nil
|
||||||
|
local bones_meta = nil
|
||||||
|
|
||||||
|
local bones_position_message = minetest.settings:get_bool("bones_position_message") == true
|
||||||
|
local pos_string = minetest.pos_to_string(player_pos)
|
||||||
|
|
||||||
|
-- return if keep inventory set or in creative mode
|
||||||
|
if bones_mode == "keep" or minetest.is_creative_enabled(player_name) then
|
||||||
|
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||||
|
". No bones placed")
|
||||||
|
if bones_position_message then
|
||||||
|
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local all_inventory = collect_all_items(player)
|
||||||
|
if bones_mode == "bones" and #all_inventory > 0 then
|
||||||
|
bones_mode, bones_pos, bones_inv, bones_meta = find_node_for_bones_on_player_death(player, player_pos)
|
||||||
|
end
|
||||||
|
if bones_mode == "drop" and #all_inventory > 0 then
|
||||||
|
all_inventory.insert(all_inventory,ItemStack("bones:bones"))
|
||||||
|
end
|
||||||
|
local dropped = dump_into(bones_mode, bones_inv, bones_pos, all_inventory)
|
||||||
|
|
||||||
local log_message
|
local log_message
|
||||||
local chat_message
|
local chat_message
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user