forked from luanti-org/minetest_game
		
	Bones mod fixes
1. don't delete protected nodes, 2. time out in loaded chunks, 3. don't crash when dying in certain nodes (like default doors or sign_lib signs)
This commit is contained in:
		@@ -21,6 +21,9 @@ bones.bones_formspec =
 | 
				
			|||||||
	"list[current_player;main;0,6.08;8,3;8]"..
 | 
						"list[current_player;main;0,6.08;8,3;8]"..
 | 
				
			||||||
	default.get_hotbar_bg(0,4.85)
 | 
						default.get_hotbar_bg(0,4.85)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local share_bones_time = tonumber(minetest.setting_get("share_bones_time") or 1200)
 | 
				
			||||||
 | 
					local share_bones_time_early = tonumber(minetest.setting_get("share_bones_time_early") or (share_bones_time/4))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
minetest.register_node("bones:bones", {
 | 
					minetest.register_node("bones:bones", {
 | 
				
			||||||
	description = "Bones",
 | 
						description = "Bones",
 | 
				
			||||||
	tiles = {
 | 
						tiles = {
 | 
				
			||||||
@@ -96,23 +99,47 @@ minetest.register_node("bones:bones", {
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	on_timer = function(pos, elapsed)
 | 
						on_timer = function(pos, elapsed)
 | 
				
			||||||
		local meta = minetest.get_meta(pos)
 | 
							local meta = minetest.get_meta(pos)
 | 
				
			||||||
		local time = meta:get_int("time")+elapsed
 | 
							local time = meta:get_int("time") + elapsed
 | 
				
			||||||
		local publish = 1200
 | 
							if time >= share_bones_time then
 | 
				
			||||||
		if tonumber(minetest.setting_get("share_bones_time")) then
 | 
					 | 
				
			||||||
			publish = tonumber(minetest.setting_get("share_bones_time"))
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
		if publish == 0 then
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		end
 | 
					 | 
				
			||||||
		if time >= publish then
 | 
					 | 
				
			||||||
			meta:set_string("infotext", meta:get_string("owner").."'s old bones")
 | 
								meta:set_string("infotext", meta:get_string("owner").."'s old bones")
 | 
				
			||||||
			meta:set_string("owner", "")
 | 
								meta:set_string("owner", "")
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
 | 
								meta:set_int("time", time)
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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 not node_definition then
 | 
				
			||||||
 | 
							-- only replace nodes that are not protected
 | 
				
			||||||
 | 
							return not minetest.is_protected(pos, player:get_player_name())
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- allow replacing air and liquids
 | 
				
			||||||
 | 
						if node_name == "air" or node_definition.liquidtype ~= "none" then
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- don't replace filled chests and other nodes that don't allow it
 | 
				
			||||||
 | 
						local can_dig_func = node_definition.can_dig
 | 
				
			||||||
 | 
						if can_dig_func and not can_dig_func(pos, player) then
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- default to each nodes buildable_to; if a placed block would replace it, why shouldn't bones?
 | 
				
			||||||
 | 
						-- flowers being squished by bones are more realistical than a squished stone, too
 | 
				
			||||||
 | 
						-- exception are of course any protected buildable_to
 | 
				
			||||||
 | 
						return node_definition.buildable_to and not minetest.is_protected(pos, player:get_player_name())
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
minetest.register_on_dieplayer(function(player)
 | 
					minetest.register_on_dieplayer(function(player)
 | 
				
			||||||
	if minetest.setting_getbool("creative_mode") then
 | 
						if minetest.setting_getbool("creative_mode") then
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -132,10 +159,13 @@ minetest.register_on_dieplayer(function(player)
 | 
				
			|||||||
	local player_name = player:get_player_name()
 | 
						local player_name = player:get_player_name()
 | 
				
			||||||
	local player_inv = player:get_inventory()
 | 
						local player_inv = player:get_inventory()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local nn = minetest.get_node(pos).name
 | 
						if (not may_replace(pos, player)) then
 | 
				
			||||||
	if minetest.registered_nodes[nn].can_dig and
 | 
							if (may_replace({x=pos.x, y=pos.y+1, z=pos.z}, player)) then
 | 
				
			||||||
		not minetest.registered_nodes[nn].can_dig(pos, 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
 | 
				
			||||||
 | 
								pos.y = pos.y+1
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
			-- drop items instead of delete
 | 
								-- drop items instead of delete
 | 
				
			||||||
			for i=1,player_inv:get_size("main") do
 | 
								for i=1,player_inv:get_size("main") do
 | 
				
			||||||
				minetest.add_item(pos, player_inv:get_stack("main", i))
 | 
									minetest.add_item(pos, player_inv:get_stack("main", i))
 | 
				
			||||||
@@ -148,9 +178,9 @@ minetest.register_on_dieplayer(function(player)
 | 
				
			|||||||
			player_inv:set_list("craft", {})
 | 
								player_inv:set_list("craft", {})
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	minetest.dig_node(pos)
 | 
						minetest.set_node(pos, {name="bones:bones", param2=param2})
 | 
				
			||||||
	minetest.add_node(pos, {name="bones:bones", param2=param2})
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	local meta = minetest.get_meta(pos)
 | 
						local meta = minetest.get_meta(pos)
 | 
				
			||||||
	local inv = meta:get_inventory()
 | 
						local inv = meta:get_inventory()
 | 
				
			||||||
@@ -171,10 +201,19 @@ minetest.register_on_dieplayer(function(player)
 | 
				
			|||||||
	player_inv:set_list("craft", {})
 | 
						player_inv:set_list("craft", {})
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	meta:set_string("formspec", bones.bones_formspec)
 | 
						meta:set_string("formspec", bones.bones_formspec)
 | 
				
			||||||
	meta:set_string("infotext", player_name.."'s fresh bones")
 | 
					 | 
				
			||||||
	meta:set_string("owner", player_name)
 | 
						meta:set_string("owner", player_name)
 | 
				
			||||||
	meta:set_int("time", 0)
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	local timer  = minetest.get_node_timer(pos)
 | 
						if share_bones_time ~= 0 then
 | 
				
			||||||
	timer:start(10)
 | 
							meta:set_string("infotext", player_name.."'s fresh bones")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if share_bones_time_early == 0 or not minetest.is_protected(pos, player_name) then
 | 
				
			||||||
 | 
								meta:set_int("time", 0)
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								meta:set_int("time", (share_bones_time - share_bones_time_early))
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							minetest.get_node_timer(pos):start(10)
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							meta:set_string("infotext", player_name.."'s bones")
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user