From a85312dfeb568ec64be9b33bedfb5e247c0ac45e Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Thu, 12 Apr 2018 21:54:30 +0200 Subject: [PATCH] drop items if inventory is full --- init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index b3f8154..2159cd7 100644 --- a/init.lua +++ b/init.lua @@ -159,11 +159,13 @@ end -- -- Add tree items to the players inventory -- -local function add_to_inventory(digger, name, len) +local function add_to_inventory(digger, name, len, pos) local inv = digger:get_inventory() local items = ItemStack(name .. " " .. len) if inv and items and inv:room_for_item("main", items) then inv:add_item("main", items) + else + minetest.item_drop(items, digger, pos) end end @@ -181,7 +183,7 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger) -- Fell the tree local radius = lTrees[oldnode.name].radius or 0 local num_nodes = remove_tree(pos, radius, oldnode.name) - add_to_inventory(digger, oldnode.name, num_nodes) + add_to_inventory(digger, oldnode.name, num_nodes, pos) add_wear(digger, oldnode, num_nodes) minetest.log("action", digger:get_player_name().." fells "..oldnode.name.. " ("..num_nodes.." items)".." at "..minetest.pos_to_string(pos))