Skip to content

Commit 4e402ec

Browse files
authored
Fix crash if bones punched by non-player (#3146)
1 parent d89170c commit 4e402ec

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

mods/bones/init.lua

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ local function is_owner(pos, name)
1616
return false
1717
end
1818

19+
local function drop(pos, itemstack)
20+
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
21+
if obj then
22+
obj:set_velocity({
23+
x = math.random(-10, 10) / 9,
24+
y = 5,
25+
z = math.random(-10, 10) / 9,
26+
})
27+
end
28+
end
29+
30+
local function drop_contents(pos)
31+
local inv = minetest.get_meta(pos):get_inventory()
32+
33+
for i = 1, inv:get_size("main") do
34+
local stk = inv:get_stack("main", i)
35+
drop(pos, stk)
36+
end
37+
minetest.remove_node(pos)
38+
end
39+
1940
local bones_formspec =
2041
"size[8,9]" ..
2142
"list[current_name;main;0,0.3;8,4;]" ..
@@ -87,6 +108,11 @@ local bones_def = {
87108
return
88109
end
89110

111+
if not player:is_player() then
112+
drop_contents(pos)
113+
return
114+
end
115+
90116
if minetest.get_meta(pos):get_string("infotext") == "" then
91117
return
92118
end
@@ -171,17 +197,6 @@ local function may_replace(pos, player)
171197
return node_definition.buildable_to
172198
end
173199

174-
local drop = function(pos, itemstack)
175-
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
176-
if obj then
177-
obj:set_velocity({
178-
x = math.random(-10, 10) / 9,
179-
y = 5,
180-
z = math.random(-10, 10) / 9,
181-
})
182-
end
183-
end
184-
185200
local player_inventory_lists = { "main", "craft" }
186201
bones.player_inventory_lists = player_inventory_lists
187202

0 commit comments

Comments
 (0)