Simplify train and rail logic and consolidate integration tests

This commit is contained in:
2026-09-13 21:55:44 +03:00
parent c39e91d836
commit 2c651a12fc
46 changed files with 2660 additions and 1233 deletions
@@ -8,21 +8,28 @@ import net.minecraft.world.level.gamerules.GameRules;
/** Match copper's random-tick selection, age neighborhood and oxidation probability. */
final class RailOxidation {
private RailOxidation() {}
static boolean advance(ServerLevel level,BlockPos pos,RailKind kind) {
if(kind.waxed() || kind.age()==3 || !level.isPositionEntityTicking(pos))return false;
int rate=level.getGameRules().get(GameRules.RANDOM_TICK_SPEED);
double chance=1-Math.pow(1-.05688889/4096,rate);
if(level.getRandom().nextDouble()>=chance)return false;
int older=0,same=0;
for(var other:BlockPos.withinManhattan(pos,4,4,4)) {
int distance=other.distManhattan(pos);if(distance>4)break;if(distance==0 || !level.hasChunkAt(other))continue;
int age=-1;
var rail=Rails.find(level,other);
if(rail!=null && !rail.waxed())age=rail.age();
else if(level.getBlockState(other).getBlock() instanceof WeatheringCopper copper)age=copper.getAge().ordinal();
if(age<0)continue;if(age<kind.age())return false;if(age>kind.age())older++;else same++;
static boolean advance(ServerLevel level, BlockPos pos, RailKind kind) {
if (kind.waxed() || kind.age() == 3 || !level.isPositionEntityTicking(pos)) return false;
int rate = level.getGameRules().get(GameRules.RANDOM_TICK_SPEED);
double chance = 1 - Math.pow(1 - .05688889 / 4096, rate);
if (level.getRandom().nextDouble() >= chance) return false;
int older = 0, same = 0;
for (var other : BlockPos.withinManhattan(pos, 4, 4, 4)) {
int distance = other.distManhattan(pos);
if (distance > 4) break;
if (distance == 0 || !level.hasChunkAt(other)) continue;
int age = -1;
var rail = Rails.find(level, other);
if (rail != null && !rail.waxed()) age = rail.age();
else if (level.getBlockState(other).getBlock() instanceof WeatheringCopper copper)
age = copper.getAge().ordinal();
if (age < 0) continue;
if (age < kind.age()) return false;
if (age > kind.age()) older++;
else same++;
}
double ratio=(older+1.0)/(older+same+1.0);
return level.getRandom().nextDouble()<ratio*ratio*(kind.age()==0?.75:1);
double ratio = (older + 1.0) / (older + same + 1.0);
return level.getRandom().nextDouble() < ratio * ratio * (kind.age() == 0 ? .75 : 1);
}
}