1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2024-12-27 03:10:24 +01:00

Try to fix some bugs that happen on server restart

This commit is contained in:
Novatux 2014-07-01 18:42:52 +02:00
parent d532e646f6
commit 99a902a8b8

View File

@ -361,7 +361,8 @@ minetest.register_entity("pipeworks:tubed_item", {
initial_sprite_basepos = {x = 0, y = 0}, initial_sprite_basepos = {x = 0, y = 0},
is_visible = false, is_visible = false,
start_pos = {}, start_pos = {},
route={} route = {},
removed = false
}, },
itemstring = '', itemstring = '',
@ -399,7 +400,9 @@ minetest.register_entity("pipeworks:tubed_item", {
end, end,
get_staticdata = function(self) get_staticdata = function(self)
if self.start_pos==nil then return end if self.start_pos == nil or self.removed then
return
end
local velocity = self.object:getvelocity() local velocity = self.object:getvelocity()
self.object:setpos(self.start_pos) self.object:setpos(self.start_pos)
return minetest.serialize({ return minetest.serialize({
@ -428,7 +431,16 @@ minetest.register_entity("pipeworks:tubed_item", {
self:set_item(item.itemstring) self:set_item(item.itemstring)
end, end,
remove = function(self)
self.object:remove()
self.removed = true
self.itemstring = ''
end,
on_step = function(self, dtime) on_step = function(self, dtime)
if self.removed then
return
end
if self.start_pos == nil then if self.start_pos == nil then
local pos = self.object:getpos() local pos = self.object:getpos()
self.start_pos = roundpos(pos) self.start_pos = roundpos(pos)
@ -481,7 +493,7 @@ minetest.register_entity("pipeworks:tubed_item", {
leftover = stack leftover = stack
end end
if leftover:is_empty() then if leftover:is_empty() then
self.object:remove() self:remove()
return return
end end
velocity.x = -velocity.x velocity.x = -velocity.x
@ -497,7 +509,7 @@ minetest.register_entity("pipeworks:tubed_item", {
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air") drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
if drop_pos then if drop_pos then
minetest.item_drop(stack, "", drop_pos) minetest.item_drop(stack, "", drop_pos)
self.object:remove() self:remove()
end end
end end
end end