Merge pull request #9 from Thomas--S/signs-dig-error

Signs: Fix potential after_dig error
This commit is contained in:
Joachim Stolberg 2020-09-26 20:38:06 +02:00 committed by GitHub
commit d65a26d4ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
lib.lua
View File

@ -229,10 +229,16 @@ function signs_bot.lib.after_dig_sign_node(pos, oldnode, oldmetadata, digger)
smeta:set_int("err_code", tonumber(oldmetadata.fields.err_code))
smeta:set_string("err_msg", oldmetadata.fields.err_msg or "")
end
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
local left_over = inv:add_item("main", sign)
if left_over:get_count() > 0 then
local player_name = digger:get_player_name()
-- See https://github.com/minetest/minetest/blob/34e3ede8eeb05e193e64ba3d055fc67959d87d86/doc/lua_api.txt#L6222
if player_name == "" then
minetest.add_item(pos, sign)
else
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
local left_over = inv:add_item("main", sign)
if left_over:get_count() > 0 then
minetest.add_item(pos, sign)
end
end
end