Skip to content

Commit

Permalink
Fix crash if bones punched by non-player (minetest#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
berengma authored and MoNTE48 committed Sep 22, 2024
1 parent c616149 commit ef69157
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions mods/bones/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ local function is_owner(pos, name)
return false
end

local function drop(pos, itemstack)
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
if obj then
obj:set_velocity({
x = math.random(-10, 10) / 9,
y = 5,
z = math.random(-10, 10) / 9,
})
end
end

local function drop_contents(pos)
local inv = minetest.get_meta(pos):get_inventory()

for i = 1, inv:get_size("main") do
local stk = inv:get_stack("main", i)
drop(pos, stk)
end
minetest.remove_node(pos)
end

local bones_formspec =
"size[8,9]" ..
"list[current_name;main;0,0.3;8,4;]" ..
Expand Down Expand Up @@ -87,6 +108,11 @@ local bones_def = {
return
end

if not player:is_player() then
drop_contents(pos)
return
end

if minetest.get_meta(pos):get_string("infotext") == "" then
return
end
Expand Down Expand Up @@ -171,17 +197,6 @@ local function may_replace(pos, player)
return node_definition.buildable_to
end

local drop = function(pos, itemstack)
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
if obj then
obj:set_velocity({
x = math.random(-10, 10) / 9,
y = 5,
z = math.random(-10, 10) / 9,
})
end
end

local player_inventory_lists = { "main", "craft" }
bones.player_inventory_lists = player_inventory_lists

Expand Down

0 comments on commit ef69157

Please sign in to comment.