1
0
Fork 0

Fix items not falling again after failed collect

This commit is contained in:
Wuzzy 2017-05-27 17:53:36 +02:00
parent db26ba2191
commit f116bcfb48
1 changed files with 19 additions and 1 deletions

View File

@ -70,6 +70,9 @@ minetest.register_globalstep(function(dtime)
if object:get_luaentity()._magnet_timer > 0 and object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time then if object:get_luaentity()._magnet_timer > 0 and object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time then
if inv and inv:room_for_item("main", ItemStack(itemstring)) then if inv and inv:room_for_item("main", ItemStack(itemstring)) then
object:get_luaentity()._magnet_active = true
object:get_luaentity()._collector_timer = 0
--modified simplemobs api --modified simplemobs api
local pos1 = pos local pos1 = pos
@ -131,7 +134,11 @@ minetest.register_globalstep(function(dtime)
end, {player, object}) end, {player, object})
end end
end end
else
object:get_luaentity()._magnet_active = false
end end
else
object:get_luaentity()._magnet_active = false
end end
if object:get_luaentity()._magnet_timer > 1 then if object:get_luaentity()._magnet_timer > 1 then
@ -320,6 +327,9 @@ core.register_entity(":__builtin:item", {
self.itemstring = staticdata self.itemstring = staticdata
end end
self._magnet_timer = 0 self._magnet_timer = 0
self._magnet_active = false
-- How long ago the last possible collector was detected. nil = none in this session
self._collector_timer = nil
self.object:set_armor_groups({immortal = 1}) self.object:set_armor_groups({immortal = 1})
self.object:setvelocity({x = 0, y = 2, z = 0}) self.object:setvelocity({x = 0, y = 2, z = 0})
self.object:setacceleration({x = 0, y = -get_gravity(), z = 0}) self.object:setacceleration({x = 0, y = -get_gravity(), z = 0})
@ -378,6 +388,9 @@ core.register_entity(":__builtin:item", {
on_step = function(self, dtime) on_step = function(self, dtime)
self.age = self.age + dtime self.age = self.age + dtime
if self._collector_timer ~= nil then
self._collector_timer = self._collector_timer + dtime
end
if time_to_live > 0 and self.age > time_to_live then if time_to_live > 0 and self.age > time_to_live then
self.itemstring = '' self.itemstring = ''
self.object:remove() self.object:remove()
@ -386,6 +399,11 @@ core.register_entity(":__builtin:item", {
local p = self.object:getpos() local p = self.object:getpos()
local node = core.get_node_or_nil(p) local node = core.get_node_or_nil(p)
local in_unloaded = (node == nil) local in_unloaded = (node == nil)
-- If no collector was found for a long enough time, declare the magnet as disabled
if self._magnet_active and (self._collector_timer == nil or (self._collector_timer > item_drop_settings.magnet_time)) then
self._magnet_active = false
end
if in_unloaded and self.physical_state == true then if in_unloaded and self.physical_state == true then
-- Don't infinetly fall into unloaded map -- Don't infinetly fall into unloaded map
self.object:setvelocity({x = 0, y = 0, z = 0}) self.object:setvelocity({x = 0, y = 0, z = 0})
@ -458,7 +476,7 @@ core.register_entity(":__builtin:item", {
self.object:set_properties({physical = false}) self.object:set_properties({physical = false})
end end
else else
if not self.physical_state then if not self.physical_state and self._magnet_active == false then
self.object:setvelocity({x = 0, y = 0, z = 0}) self.object:setvelocity({x = 0, y = 0, z = 0})
self.object:setacceleration({x = 0, y = -get_gravity(), z = 0}) self.object:setacceleration({x = 0, y = -get_gravity(), z = 0})
self.physical_state = true self.physical_state = true