Add code to reattach carts to rail when data corruption occurs, fix bug in last commit that caused carts to bury into the ground

This commit is contained in:
teknomunk 2024-03-09 17:28:23 +00:00
parent adddaec69a
commit b51496ad8e

View file

@ -272,8 +272,15 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
local pos = staticdata.connected_at local pos = staticdata.connected_at
if not pos then if not pos then
pos = self.object:get_pos() pos = self.object:get_pos()
print("TODO: handle detached cart behavior") -- Try to reattach
--return local rounded_pos = vector.round(pos)
if mcl_minecarts:is_rail(rounded_pos) and vector.distance(pos, rounded_pos) < 0.25 then
-- Reattach
staticdata.connected_at = rounded_pos
pos = rounded_pos
else
print("TODO: handle detached cart behavior")
end
end end
-- Fix railtype field -- Fix railtype field
@ -525,11 +532,14 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
-- Complete moving thru this block into the next, reverse direction, and put us back at the same position we were at -- Complete moving thru this block into the next, reverse direction, and put us back at the same position we were at
staticdata.velocity = staticdata.velocity * -1 staticdata.velocity = staticdata.velocity * -1
staticdata.dir = -staticdata.dir next_dir = -staticdata.dir
pos = pos + staticdata.dir pos = pos + staticdata.dir
staticdata.distance = 1 - staticdata.distance staticdata.distance = 1 - staticdata.distance
staticdata.connected_at = pos staticdata.connected_at = pos
local next_dir,_ = mcl_minecarts:get_rail_direction(pos + staticdata.dir, next_dir, nil, nil, staticdata.railtype)
staticdata.dir = next_dir
update_cart_orientation(self,staticdata) update_cart_orientation(self,staticdata)
end end
end end