Skip to content

Commit

Permalink
Merge pull request #681 from fixrtm/fix-slow-train
Browse files Browse the repository at this point in the history
fix: vehicle stops at low speed
  • Loading branch information
anatawa12 committed Jul 1, 2023
2 parents 69b2686 + 269b34d commit 6cccd99
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-SNAPSHOTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
- Directory based ModelPacks not working `#677`
- Getting onto bogie of moving train may drive train opposite direction `#680`
- This also reverts `#633` because it's broken for long train
- Slow trains will get too slow `#681`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Thanks to prepare-changelog.sh, we have some macros.
- we don't need to remove original signature of `RenderElectricalWiring.renderAllWire`
- Directory based ModelPacks not working `#677`
- Getting onto bogie of moving train may drive train opposite direction `#680`
- Slow trains will get too slow `#681`

### Security

Expand Down
53 changes: 42 additions & 11 deletions src/main/rtm-patches/jp/ngt/rtm/entity/train/EntityBogie.java.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
--- a/jp/ngt/rtm/entity/train/EntityBogie.java
+++ b/jp/ngt/rtm/entity/train/EntityBogie.java
@@ -126,11 +126,11 @@
@@ -44,10 +44,11 @@
private TileEntityLargeRailCore currentRailObj;
private RailMap currentRailMap;
private final double[] posBuf = new double[3];
private final float[] rotationBuf = new float[4];
private int split = -1;
+ private static final int SPLITS_PER_METER = 360; //(Minimum Speed[km/h] / 3.6 / 20[tick])^-1 e.g. (0.2/3.6/20)^-1 = 360
private int prevPosIndex;
private float jointDelay;
private boolean reverbSound;
private int jointIndex;
private int existCount;
@@ -126,11 +127,11 @@
return BogieController.MotionState.FLY;
} else {
RailMap railmap = this.currentRailMap;
int i = 0;
if (frontBogie != null && this.prevPosIndex != -1) {
- int j = (int)((speed + 0.25F) * 32.0F);
+ int j = (int)((Math.abs(speed) + 0.25F) * 32.0F);
+ int j = (int)((Math.abs(speed) + 0.25F) * SPLITS_PER_METER);
int k = this.prevPosIndex - j;
int l = this.prevPosIndex + j;
int i1 = k < 0 ? 0 : k;
int j1 = l > this.split ? this.split : l;
double[] adouble = frontBogie.getPosBuf();
@@ -171,11 +171,11 @@
@@ -171,11 +172,11 @@
this.rotationBuf[0] = f2;
this.rotationBuf[1] = f3;
this.rotationBuf[2] = f1;
Expand All @@ -26,7 +38,7 @@
}
}

@@ -196,18 +196,20 @@
@@ -196,19 +197,21 @@
TileEntityLargeRailCore tileentitylargerailcore = this.getRail(px, py, pz);
if (tileentitylargerailcore == null) {
return false;
Expand All @@ -43,14 +55,16 @@
+ railMap = tileentitylargerailcore.getRailMap(this);
}

- this.split = (int)(this.currentRailMap.getLength() * 32.0D);
+ this.currentRailObj = tileentitylargerailcore;
+ this.currentRailMap = railMap;
this.split = (int)(this.currentRailMap.getLength() * 32.0D);
+ this.split = (int)(this.currentRailMap.getLength() * SPLITS_PER_METER);
this.prevPosIndex = -1;
this.onChangeRail(tileentitylargerailcore);
}

@@ -227,14 +229,17 @@
return true;
@@ -227,14 +230,17 @@
return null;
}

Expand All @@ -72,7 +86,7 @@
}

protected boolean reverseJointArray() {
@@ -245,13 +250,13 @@
@@ -245,13 +251,13 @@

protected void playJointSound() {
EntityTrainBase entitytrainbase = this.getTrain();
Expand All @@ -88,7 +102,7 @@
int j = this.reverseJointArray() ? i - this.jointIndex - 1 : this.jointIndex;
++this.jointIndex;
int k = this.reverseJointArray() ? i - this.jointIndex - 1 : this.jointIndex;
@@ -287,14 +292,23 @@
@@ -287,14 +293,23 @@

public final void onUpdate() {
if (!this.world.isRemote && !this.tracked) {
Expand All @@ -112,7 +126,7 @@
}

public void onBogieUpdate() {
@@ -309,11 +323,11 @@
@@ -309,11 +324,11 @@

}

Expand All @@ -125,7 +139,24 @@

}

@@ -491,10 +505,14 @@
@@ -349,13 +364,14 @@

public boolean attackEntityFrom(DamageSource par1, float par2) {
if (this.getTrain() != null && !this.getTrain().isDead) {
return this.getTrain().attackEntityFrom(par1, par2);
} else {
- if (!this.world.isRemote) {
+ /*if (!this.world.isRemote) {
this.setDead();
- }
+ }*/
+ this.setDead();

return true;
}
}

@@ -491,10 +507,14 @@
public void addVelocity(double par1, double par3, double par5) {
}

Expand All @@ -140,7 +171,7 @@
}
} else if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() == RTMItem.paddle) {
return true;
@@ -578,6 +596,18 @@
@@ -578,6 +598,18 @@
}

public int getProhibitedAction() {
Expand Down

0 comments on commit 6cccd99

Please sign in to comment.