Check if hitter has inventory when punching item
authorBlockMen <nmuelll@web.de>
Sun, 25 Oct 2015 17:15:31 +0000 (18:15 +0100)
committerBlockMen <nmuelll@web.de>
Sun, 25 Oct 2015 17:15:31 +0000 (18:15 +0100)
Fixes #3280

builtin/game/item_entity.lua

index 190473ceb5dca2f76ed6b5929df7b8fa3abbdd06..a8d7a186361759d95c90ffb42b8ef64956d284fa 100644 (file)
@@ -200,9 +200,10 @@ core.register_entity(":__builtin:item", {
        end,
 
        on_punch = function(self, hitter)
-               if self.itemstring ~= '' then
-                       local left = hitter:get_inventory():add_item("main", self.itemstring)
-                       if not left:is_empty() then
+               local inv = hitter:get_inventory()
+               if inv and self.itemstring ~= '' then
+                       local left = inv:add_item("main", self.itemstring)
+                       if left and not left:is_empty() then
                                self.itemstring = left:to_string()
                                return
                        end