Skip to content

Commit

Permalink
Fix division by zero in cabcar max speed
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Dec 11, 2023
1 parent e18d48a commit 511f40d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public float getValue(EntityRollingStock stock, float lever) {
case LIQUID:
return stock instanceof FreightTank ? ((FreightTank) stock).getPercentLiquidFull() / 100f : 0;
case SPEED:
return (float)Math.abs(((EntityMoveableRollingStock)stock).getCurrentSpeed().metric() /
(stock instanceof Locomotive ? ((Locomotive) stock).getDefinition().getMaxSpeed(stock.gauge).metric() : 200));
double maxSpeed = (stock instanceof Locomotive ? ((Locomotive) stock).getDefinition().getMaxSpeed(stock.gauge).metric() : 0);
if (maxSpeed == 0) {
maxSpeed = 200;
}
return (float)Math.abs(((EntityMoveableRollingStock)stock).getCurrentSpeed().metric() / maxSpeed);
case TEMPERATURE:
if (stock instanceof LocomotiveSteam) {
return ((LocomotiveSteam) stock).getBoilerTemperature() / 100f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ public void update(Vec3d particlePos, boolean enteredStroke, boolean drain_enabl

double speed = Math.abs(stock.getCurrentSpeed().minecraft());
double maxSpeed = Math.abs(stock.getDefinition().getMaxSpeed(stock.gauge).minecraft());
if (maxSpeed == 0) {
maxSpeed = 200;
}
float volume = (float) Math.max(1-speed/maxSpeed, 0.3) * Math.abs(stock.getThrottle() * stock.getReverser());
volume = (float) Math.sqrt(volume);
double fraction = 3;
Expand Down

0 comments on commit 511f40d

Please sign in to comment.