@@ -21,6 +21,9 @@ bones.bones_formspec =
21
21
" list[current_player;main;0,6.08;8,3;8]" ..
22
22
default .get_hotbar_bg (0 ,4.85 )
23
23
24
+ local share_bones_time = tonumber (minetest .setting_get (" share_bones_time" ) or 1200 )
25
+ local share_bones_time_early = tonumber (minetest .setting_get (" share_bones_time_early" ) or (share_bones_time / 4 ))
26
+
24
27
minetest .register_node (" bones:bones" , {
25
28
description = " Bones" ,
26
29
tiles = {
@@ -96,23 +99,47 @@ minetest.register_node("bones:bones", {
96
99
97
100
on_timer = function (pos , elapsed )
98
101
local meta = minetest .get_meta (pos )
99
- local time = meta :get_int (" time" )+ elapsed
100
- local publish = 1200
101
- if tonumber (minetest .setting_get (" share_bones_time" )) then
102
- publish = tonumber (minetest .setting_get (" share_bones_time" ))
103
- end
104
- if publish == 0 then
105
- return
106
- end
107
- if time >= publish then
102
+ local time = meta :get_int (" time" ) + elapsed
103
+ if time >= share_bones_time then
108
104
meta :set_string (" infotext" , meta :get_string (" owner" ).. " 's old bones" )
109
105
meta :set_string (" owner" , " " )
110
106
else
107
+ meta :set_int (" time" , time )
111
108
return true
112
109
end
113
110
end ,
114
111
})
115
112
113
+ local function may_replace (pos , player )
114
+ local node_name = minetest .get_node (pos ).name
115
+ local node_definition = minetest .registered_nodes [node_name ]
116
+
117
+ -- if the node is unknown, we let the protection mod decide
118
+ -- this is consistent with when a player could dig or not dig it
119
+ -- unknown decoration would often be removed
120
+ -- while unknown building materials in use would usually be left
121
+ if not node_definition then
122
+ -- only replace nodes that are not protected
123
+ return not minetest .is_protected (pos , player :get_player_name ())
124
+ end
125
+
126
+ -- allow replacing air and liquids
127
+ if node_name == " air" or node_definition .liquidtype ~= " none" then
128
+ return true
129
+ end
130
+
131
+ -- don't replace filled chests and other nodes that don't allow it
132
+ local can_dig_func = node_definition .can_dig
133
+ if can_dig_func and not can_dig_func (pos , player ) then
134
+ return false
135
+ end
136
+
137
+ -- default to each nodes buildable_to; if a placed block would replace it, why shouldn't bones?
138
+ -- flowers being squished by bones are more realistical than a squished stone, too
139
+ -- exception are of course any protected buildable_to
140
+ return node_definition .buildable_to and not minetest .is_protected (pos , player :get_player_name ())
141
+ end
142
+
116
143
minetest .register_on_dieplayer (function (player )
117
144
if minetest .setting_getbool (" creative_mode" ) then
118
145
return
@@ -131,26 +158,29 @@ minetest.register_on_dieplayer(function(player)
131
158
local param2 = minetest .dir_to_facedir (player :get_look_dir ())
132
159
local player_name = player :get_player_name ()
133
160
local player_inv = player :get_inventory ()
134
-
135
- local nn = minetest .get_node (pos ).name
136
- if minetest .registered_nodes [nn ].can_dig and
137
- not minetest .registered_nodes [nn ].can_dig (pos , player ) then
138
161
139
- -- drop items instead of delete
140
- for i = 1 ,player_inv :get_size (" main" ) do
141
- minetest .add_item (pos , player_inv :get_stack (" main" , i ))
142
- end
143
- for i = 1 ,player_inv :get_size (" craft" ) do
144
- minetest .add_item (pos , player_inv :get_stack (" craft" , i ))
162
+ if (not may_replace (pos , player )) then
163
+ if (may_replace ({x = pos .x , y = pos .y + 1 , z = pos .z }, player )) then
164
+ -- drop one node above if there's space
165
+ -- this should solve most cases of protection related deaths in which players dig straight down
166
+ -- yet keeps the bones reachable
167
+ pos .y = pos .y + 1
168
+ else
169
+ -- drop items instead of delete
170
+ for i = 1 ,player_inv :get_size (" main" ) do
171
+ minetest .add_item (pos , player_inv :get_stack (" main" , i ))
172
+ end
173
+ for i = 1 ,player_inv :get_size (" craft" ) do
174
+ minetest .add_item (pos , player_inv :get_stack (" craft" , i ))
175
+ end
176
+ -- empty lists main and craft
177
+ player_inv :set_list (" main" , {})
178
+ player_inv :set_list (" craft" , {})
179
+ return
145
180
end
146
- -- empty lists main and craft
147
- player_inv :set_list (" main" , {})
148
- player_inv :set_list (" craft" , {})
149
- return
150
181
end
151
182
152
- minetest .dig_node (pos )
153
- minetest .add_node (pos , {name = " bones:bones" , param2 = param2 })
183
+ minetest .set_node (pos , {name = " bones:bones" , param2 = param2 })
154
184
155
185
local meta = minetest .get_meta (pos )
156
186
local inv = meta :get_inventory ()
@@ -171,10 +201,19 @@ minetest.register_on_dieplayer(function(player)
171
201
player_inv :set_list (" craft" , {})
172
202
173
203
meta :set_string (" formspec" , bones .bones_formspec )
174
- meta :set_string (" infotext" , player_name .. " 's fresh bones" )
175
204
meta :set_string (" owner" , player_name )
176
- meta :set_int (" time" , 0 )
177
205
178
- local timer = minetest .get_node_timer (pos )
179
- timer :start (10 )
206
+ if share_bones_time ~= 0 then
207
+ meta :set_string (" infotext" , player_name .. " 's fresh bones" )
208
+
209
+ if share_bones_time_early == 0 or not minetest .is_protected (pos , player_name ) then
210
+ meta :set_int (" time" , 0 )
211
+ else
212
+ meta :set_int (" time" , (share_bones_time - share_bones_time_early ))
213
+ end
214
+
215
+ minetest .get_node_timer (pos ):start (10 )
216
+ else
217
+ meta :set_string (" infotext" , player_name .. " 's bones" )
218
+ end
180
219
end )
0 commit comments