Use initial_properties, backup old_pos for loading

This commit is contained in:
SmallJoker 2018-09-01 14:49:16 +02:00
parent 3386942d71
commit e4edb96d30

@ -19,12 +19,14 @@ function boost_cart:on_rail_step(entity, pos, distance)
end end
local cart_entity = { local cart_entity = {
physical = false, initial_properties = {
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, physical = false,
visual = "mesh", collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
mesh = "cart.x", visual = "mesh",
visual_size = {x=1, y=1}, mesh = "cart.x",
textures = {"cart.png"}, visual_size = {x=1, y=1},
textures = {"cart.png"},
},
driver = nil, driver = nil,
punched = false, -- used to re-send velocity and position punched = false, -- used to re-send velocity and position
@ -39,8 +41,8 @@ local cart_entity = {
-- Model and textures -- Model and textures
if boost_cart.mtg_compat then if boost_cart.mtg_compat then
cart_entity.mesh = "carts_cart.b3d" cart_entity.initial_properties.mesh = "carts_cart.b3d"
cart_entity.textures = {"carts_cart.png"} cart_entity.initial_properties.textures = {"carts_cart.png"}
end end
function cart_entity:on_rightclick(clicker) function cart_entity:on_rightclick(clicker)
@ -75,15 +77,19 @@ function cart_entity:on_activate(staticdata, dtime_s)
return return
end end
self.railtype = data.railtype self.railtype = data.railtype
if data.old_dir then self.old_dir = data.old_dir or self.old_dir
self.old_dir = data.old_dir self.old_pos = data.old_pos or self.old_pos
-- Correct the position when the cart drives further after the last 'step()'
if self.old_pos and boost_cart:is_rail(self.old_pos, self.railtype) then
self.object:set_pos(self.old_pos)
end end
end end
function cart_entity:get_staticdata() function cart_entity:get_staticdata()
return minetest.serialize({ return minetest.serialize({
railtype = self.railtype, railtype = self.railtype,
old_dir = self.old_dir old_dir = self.old_dir,
old_pos = self.old_pos
}) })
end end