From 5b93a54a0036135b9c9bed19c3665d3b3f9f1ae9 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 9 Mar 2024 17:28:23 +0000 Subject: [PATCH] Add code to reattach carts to rail when data corruption occurs, fix bug in last commit that caused carts to bury into the ground --- mods/ENTITIES/mcl_minecarts/init.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 253490b40..ac8b3f225 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -272,8 +272,15 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o local pos = staticdata.connected_at if not pos then pos = self.object:get_pos() - print("TODO: handle detached cart behavior") - --return + -- Try to reattach + 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 -- 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 staticdata.velocity = staticdata.velocity * -1 - staticdata.dir = -staticdata.dir + next_dir = -staticdata.dir pos = pos + staticdata.dir staticdata.distance = 1 - staticdata.distance 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) end end