Source-checkedVehicles & ships

Create Train Crash Fix

by JXSnack · for Minecraft

Fixes the issue where trains by the Create mod might crash the server due to infinite positions.

5.3KDownloads
2 yr agoLast updated
AGPL-3.0-onlyLicense
Fabric · QuiltLoaders

About Create Train Crash Fix

From Modrinth

Fixes the issue where trains by the Create mod might crash the server due to infinite positions.

Create Train Crash Fix

Fixes the crash that may occur when a train has infinite positions (even if the train data file doesn't show an infinite)

a very simple mod

Info for nerds (how it was fixed) First we've got to take a look at the issue: the train does not have an invalid position in the train data file. That means it has to be somewhere in the serialisation.

Creation of issue #6795\ August 7th, 2024

I added two mixin injections. One at createEntity (from create) and readNbt (from minecraft).

@Mixin(Carriage.DimensionalCarriageEntity.class)
public abstract class DimensionalCarriageMixin {
  @Shadow public Vec3d positionAnchor;

  @Inject(at = @At("HEAD"), method = "createEntity")
  private void sendEntityInfo(World level, boolean loadPassengers, CallbackInfo ci) {
    CreateTrainFix.LOGGER.info(positionAnchor.toString());

    if (!Double.isFinite(positionAnchor.getX()) || !Double.isFinite(positionAnchor.getY()) || !Double.isFinite(positionAnchor.getZ())) {
        CreateTrainFix.LOGGER.info("Train failed to be created, because of infinity checks.");
    }
  }
}

@Mixin(Entity.class)
public abstract class EntityMixin {
  @Shadow public abstract double getX();

  @Shadow public abstract double getY();

  @Shadow public abstract double getZ();

  @Shadow public abstract Vec3d getPos();

  @Inject(method = "readNbt", at = @At(value = "INVOKE", target = "Ljava/lang/Double;isFinite(D)Z"))
  private void checkFiniteDebug(NbtCompound nbt, CallbackInfo ci) {
    if (!Double.isFinite(getX()) || !Double.isFinite(getY()) || !Double.isFinite(getZ())) {
      CreateTrainFix.LOGGER.info("INFINITE location " + getPos());
    }
  }
}

This is what's being logged, after which it inevitably crashes. The coordinates are somehow invalid, while still being normal in the createEntity method.

[18:18:15] [Server thread/INFO]: (225.5, 58.0, -165.8600004762411)
[18:18:15] [Server thread/INFO]: INFINITE location (NaN, NaN, NaN)

After more thorough checking the NBT already comes as NaN, while the create_tracks.dat file doesn't contain anything like that. create_tracks.dat check see line 123 (heh, funny number)


~2.5 months later IThundxr proposes the idea of adding something similar to the following into the code:

serialisedEntity.remove("Pos");
serialisedEntity.put("Pos", newDoubleList(positionAnchor.x(), positionAnchor.y(), positionAnchor.z()));

This is the final concept and it works!


This is the final version of what has been added

@Inject(at = @At("HEAD"), method = "createEntity")
private void createTrainFix$fixEntity(World level, boolean loadPassengers, CallbackInfo ci) {
  try {
    // RefUtil is a class with a few methods to access private fields from the superclass.
    NbtCompound serialisedEntity = (NbtCompound) RefUtil.getPrivateFieldValue(this$0, "serialisedEntity");
    serialisedEntity.remove("Pos");
    serialisedEntity.put("Pos", newDoubleList(positionAnchor.x, positionAnchor.y, positionAnchor.z));
    // Set the value again
    RefUtil.setFieldValue(this$0, "serialisedEntity", serialisedEntity);
  } catch (NoSuchFieldException | IllegalAccessException e) {
    // If this all didn't work, throw an error
    CreateTrainFix.LOGGER.error("(CreateTrainFix) Failed to fix train position");
    throw new RuntimeException(e);
  }

  // Final check
  if (!Double.isFinite(positionAnchor.getX()) || !Double.isFinite(positionAnchor.getY()) || !Double.isFinite(positionAnchor.getZ())) {
    CreateTrainFix.LOGGER.info("Train failed to be created, because of infinity checks.");
  }
}

Highlights

From source data

Game versions

Built for Minecraft 1.20.1.

Loaders

Runs on Fabric and Quilt.

Footprint

Rated a light load on a server.

Create Train Crash Fix on Nxeon

From our catalogue
One-click install
Supported on Nxeon Minecraft servers. We download it from Modrinth, place it, and restart the server.
Server side
Required on the server
Server type needed
Fabric, Quilt
Server load
light
Smallest plan we suggest
Minecraft — 2 GB (2 GB RAM). This follows our own load rating above, not a benchmark.
Latest build
1.0.0, released 2024-10-24

Game versions by loader

LoaderGame versionsNewest
Fabric1.20.11.20.1
Quilt1.20.11.20.1

From 1 recorded build of Create Train Crash Fix.

Dependencies

  • Required: modrinth project Xbc0uyRg (modrinth, not in our catalogue)

Declared by the newest build that lists any. Required ones are installed with it on one-click installs.

Run Create Train Crash Fix on a Minecraft server

Pick a server or deploy a new one above; it is installed in one click.

What kind of mod it is

From the catalog
Listed on Modrinth as “Mods”

Vehicles & ships

Cars, boats, aircraft, ships and other things to drive or fly.

Runs on your server

From source side support

Modrinth lists Create Train Crash Fix as required on the server. Check its Modrinth page to see whether players need it too.

Compatibility

Game
Minecraft
Loaders
FabricQuilt
Runs on
Serverrequired on the server
Game versions
1.20.1

Verified at the source

  • ✓ModrinthOfficial listing, checked 2026-10-02Open ↗
  • ✓AuthorJXSnack, as published on Modrinth
  • ✓LicenseAGPL-3.0-onlyFree

Create Train Crash Fix, answered

Generated from the mod’s own source data.

Do my players need to install Create Train Crash Fix?

Modrinth lists Create Train Crash Fix as required on the server. Check its Modrinth page to see whether players need it too.

Which loaders does it support?

Fabric and Quilt.

Is it free?

Yes. Create Train Crash Fix is free to download from Modrinth. Its license is AGPL-3.0-only.

How do I add it to my Nxeon server?

Use “Add to a server” on this page, or open NxLabs from your dashboard. We install it, restart your server and switch it on.

NxLabs

Run Create Train Crash Fix on a Minecraft server.

Deploy in about a minute from $4.99 a month, then add Create Train Crash Fix in one click.