forked from minetest/minetest_game
Bones: Ability to change bones mode. Tidy up code
Add 'bones_mode' setting to minetest.conf -> Modes: bones, drop, keep Remove table 'bones' Add minetest.conf.example description Remove protection check from may_replace
This commit is contained in:
parent
db129f4ca0
commit
2df7ce20dd
@ -5,6 +5,12 @@
|
||||
# Whether creative mode (fast digging of all blocks, unlimited resources) should be enabled
|
||||
#creative_mode = false
|
||||
|
||||
# Sets the behaviour of the inventory items when a player dies.
|
||||
# "bones": Store all items inside a bone node but drop items if inside protected area
|
||||
# "drop": Drop all items on the ground
|
||||
# "keep": Player keeps all items
|
||||
#bones_mode = "bones"
|
||||
|
||||
# The time in seconds after which the bones of a dead player can be looted by everyone
|
||||
# 0 to disable
|
||||
#share_bones_time = 1200
|
||||
|
@ -1,8 +1,6 @@
|
||||
-- Minetest 0.4 mod: bones
|
||||
-- See README.txt for licensing and other information.
|
||||
|
||||
bones = {}
|
||||
|
||||
local function is_owner(pos, name)
|
||||
local owner = minetest.get_meta(pos):get_string("owner")
|
||||
if owner == "" or owner == name or minetest.check_player_privs(name, "protection_bypass") then
|
||||
@ -11,7 +9,7 @@ local function is_owner(pos, name)
|
||||
return false
|
||||
end
|
||||
|
||||
bones.bones_formspec =
|
||||
local bones_formspec =
|
||||
"size[8,9]" ..
|
||||
default.gui_bg ..
|
||||
default.gui_bg_img ..
|
||||
@ -78,11 +76,11 @@ minetest.register_node("bones:bones", {
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, player)
|
||||
if(not is_owner(pos, player:get_player_name())) then
|
||||
if not is_owner(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
if(minetest.get_meta(pos):get_string("infotext") == "") then
|
||||
if minetest.get_meta(pos):get_string("infotext") == "" then
|
||||
return
|
||||
end
|
||||
|
||||
@ -131,13 +129,9 @@ local function may_replace(pos, player)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local node_definition = minetest.registered_nodes[node_name]
|
||||
|
||||
-- if the node is unknown, we let the protection mod decide
|
||||
-- this is consistent with when a player could dig or not dig it
|
||||
-- unknown decoration would often be removed
|
||||
-- while unknown building materials in use would usually be left
|
||||
-- if the node is unknown, we return false
|
||||
if not node_definition then
|
||||
-- only replace nodes that are not protected
|
||||
return not minetest.is_protected(pos, player:get_player_name())
|
||||
return false
|
||||
end
|
||||
|
||||
-- allow replacing air and liquids
|
||||
@ -157,8 +151,26 @@ local function may_replace(pos, player)
|
||||
return node_definition.buildable_to and not minetest.is_protected(pos, player:get_player_name())
|
||||
end
|
||||
|
||||
local drop = function(pos, itemstack)
|
||||
local obj = core.add_item(pos, itemstack:take_item(itemstack:get_count()))
|
||||
if obj then
|
||||
obj:setvelocity({
|
||||
x = math.random(-10, 10) / 9,
|
||||
y = 5,
|
||||
z = math.random(-10, 10) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
|
||||
local bones_mode = minetest.setting_get("bones_mode") or "bones"
|
||||
if bones_mode ~= "bones" and bones_mode ~= "drop" and bones_mode ~= "keep" then
|
||||
bones_mode = "bones"
|
||||
end
|
||||
|
||||
-- return if keep inventory set or in creative mode
|
||||
if bones_mode == "keep" or minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
|
||||
@ -168,34 +180,38 @@ minetest.register_on_dieplayer(function(player)
|
||||
return
|
||||
end
|
||||
|
||||
local pos = player:getpos()
|
||||
pos.x = math.floor(pos.x+0.5)
|
||||
pos.y = math.floor(pos.y+0.5)
|
||||
pos.z = math.floor(pos.z+0.5)
|
||||
local param2 = minetest.dir_to_facedir(player:get_look_dir())
|
||||
local pos = vector.round(player:getpos())
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
if (not may_replace(pos, player)) then
|
||||
if (may_replace({x=pos.x, y=pos.y+1, z=pos.z}, player)) then
|
||||
-- drop one node above if there's space
|
||||
-- this should solve most cases of protection related deaths in which players dig straight down
|
||||
-- yet keeps the bones reachable
|
||||
-- check if it's possible to place bones, if not go 1 higher
|
||||
if bones_mode == "bones" and not may_replace(pos, player) then
|
||||
pos.y = pos.y + 1
|
||||
else
|
||||
-- drop items instead of delete
|
||||
for i=1,player_inv:get_size("main") do
|
||||
minetest.add_item(pos, player_inv:get_stack("main", i))
|
||||
end
|
||||
for i=1,player_inv:get_size("craft") do
|
||||
minetest.add_item(pos, player_inv:get_stack("craft", i))
|
||||
end
|
||||
-- empty lists main and craft
|
||||
player_inv:set_list("main", {})
|
||||
player_inv:set_list("craft", {})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- still cannot place bones? change mode to 'drop'
|
||||
if bones_mode == "bones" and not may_replace(pos, player) then
|
||||
bones_mode = "drop"
|
||||
end
|
||||
|
||||
if bones_mode == "drop" then
|
||||
|
||||
-- drop inventory items
|
||||
for i = 1, player_inv:get_size("main") do
|
||||
drop(pos, player_inv:get_stack("main", i))
|
||||
end
|
||||
player_inv:set_list("main", {})
|
||||
|
||||
-- drop crafting grid items
|
||||
for i = 1, player_inv:get_size("craft") do
|
||||
drop(pos, player_inv:get_stack("craft", i))
|
||||
end
|
||||
player_inv:set_list("craft", {})
|
||||
|
||||
drop(pos, ItemStack("bones:bones"))
|
||||
return
|
||||
end
|
||||
|
||||
local param2 = minetest.dir_to_facedir(player:get_look_dir())
|
||||
minetest.set_node(pos, {name = "bones:bones", param2 = param2})
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -209,14 +225,14 @@ minetest.register_on_dieplayer(function(player)
|
||||
inv:add_item("main", stack)
|
||||
else
|
||||
--drop if no space left
|
||||
minetest.add_item(pos, stack)
|
||||
drop(pos, stack)
|
||||
end
|
||||
end
|
||||
|
||||
player_inv:set_list("main", {})
|
||||
player_inv:set_list("craft", {})
|
||||
|
||||
meta:set_string("formspec", bones.bones_formspec)
|
||||
meta:set_string("formspec", bones_formspec)
|
||||
meta:set_string("owner", player_name)
|
||||
|
||||
if share_bones_time ~= 0 then
|
||||
|
Loading…
Reference in New Issue
Block a user