Skip to content

Commit

Permalink
Fix recursive client move
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Sep 10, 2017
1 parent 0a079e8 commit 65b24e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/cam72cam/immersiverailroading/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -198,6 +203,10 @@ private void recursiveMove(EntityCoupleableRollingStock prev) {
continue;
}

if (coupled == this) {
this.decouple(coupler);
}

// THIS UPDATES LAST KNOWN POS
setCoupled(coupler, coupled);

Expand Down Expand Up @@ -263,7 +272,7 @@ private void recursiveMove(EntityCoupleableRollingStock prev) {
}

coupled.moveRollingStock(distance);
coupled.recursiveMove(this);
coupled.recursiveMove(this, depth+1);
}
}

Expand Down

0 comments on commit 65b24e6

Please sign in to comment.