Don't crash if an item gets dropped into unloaded space
authortenplus1 <tenplus1@users.noreply.github.com>
Thu, 14 May 2015 10:35:24 +0000 (11:35 +0100)
committerest31 <MTest31@outlook.com>
Thu, 14 May 2015 22:15:25 +0000 (00:15 +0200)
Items dropped into unloaded map space will crash game so here's a fix...

builtin/game/item_entity.lua

index d848fd8551a1884237518317f5bc9a671d0bc387..6425a10aab6cd7b6d4db8582b6e3878bdbf02c18 100644 (file)
@@ -155,7 +155,17 @@ core.register_entity(":__builtin:item", {
                end
                local p = self.object:getpos()
                p.y = p.y - 0.5
-               local nn = core.get_node(p).name
+               local node = core.get_node_or_nil(p)
+               local in_unloaded = (node == nil)
+               if in_unloaded then
+                       -- Don't infinetly fall into unloaded map
+                       self.object:setvelocity({x = 0, y = 0, z = 0})
+                       self.object:setacceleration({x = 0, y = 0, z = 0})
+                       self.physical_state = false
+                       self.object:set_properties({physical = false})
+                       return
+               end
+               local nn = node.name
                -- If node is not registered or node is walkably solid and resting on nodebox
                local v = self.object:getvelocity()
                if not core.registered_nodes[nn] or core.registered_nodes[nn].walkable and v.y == 0 then