From 65b24e6b7a098620335ccd276aaf300288515c47 Mon Sep 17 00:00:00 2001 From: Christian Mesh Date: Sun, 10 Sep 2017 12:32:37 -0400 Subject: [PATCH] Fix recursive client move --- .../cam72cam/immersiverailroading/Config.java | 3 +++ .../entity/EntityCoupleableRollingStock.java | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/cam72cam/immersiverailroading/Config.java b/src/main/java/cam72cam/immersiverailroading/Config.java index 09758af3b..b534df5e6 100644 --- a/src/main/java/cam72cam/immersiverailroading/Config.java +++ b/src/main/java/cam72cam/immersiverailroading/Config.java @@ -33,4 +33,7 @@ public class Config { @Comment({"Print extra chunk loading info"}) public static boolean debugChunkLoading = true; + + @Comment({"Max length of a train"}) + public static int maxTrainLength = 100; } diff --git a/src/main/java/cam72cam/immersiverailroading/entity/EntityCoupleableRollingStock.java b/src/main/java/cam72cam/immersiverailroading/entity/EntityCoupleableRollingStock.java index c46788176..15f13dd75 100644 --- a/src/main/java/cam72cam/immersiverailroading/entity/EntityCoupleableRollingStock.java +++ b/src/main/java/cam72cam/immersiverailroading/entity/EntityCoupleableRollingStock.java @@ -182,14 +182,19 @@ public void setDead() { public void moveCoupledRollingStock(Float moveDistance) { this.moveRollingStock(moveDistance); if (Math.abs(moveDistance) > 0.01) { - recursiveMove(null); + recursiveMove(null, 0); } } // This breaks with looped rolling stock - private void recursiveMove(EntityCoupleableRollingStock prev) { + private void recursiveMove(EntityCoupleableRollingStock prev, int depth) { ChunkManager.flagEntityPos(this); + if (depth > Config.maxTrainLength) { + ImmersiveRailroading.logger.warn("TRAIN TOO LONG!"); + return; + } + for (CouplerType coupler : CouplerType.values()) { EntityCoupleableRollingStock coupled = this.getCoupled(coupler); @@ -198,6 +203,10 @@ private void recursiveMove(EntityCoupleableRollingStock prev) { continue; } + if (coupled == this) { + this.decouple(coupler); + } + // THIS UPDATES LAST KNOWN POS setCoupled(coupler, coupled); @@ -263,7 +272,7 @@ private void recursiveMove(EntityCoupleableRollingStock prev) { } coupled.moveRollingStock(distance); - coupled.recursiveMove(this); + coupled.recursiveMove(this, depth+1); } }