Create Train Crash Fix

Quick rating

Create Train Crash Fix

No reviews yet

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

Mod Loaders
Fabric
Quilt
Minecraft

Community voices

Reviews

Versions
Loading versions…
Match includes

Click once to include, again to exclude, again to clear

Rating Any
Any 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
Min
Max
Play Status
Reviews
Time Played
hrs+
Verified developers only
Has developer response
List view
Grid view
Compact view
Sort by
Date
Rating
Helpful
Unhelpful
Edited
Sort ascending
Delete this review?

This removes your review from the project. You can write a new review after.

Review submitted for moderation

Your review has been sent to moderators, who will check that it meets our guidelines before it appears publicly.

No reviews yet. Be the first to review this project!

Get it on

Available Platforms

Compatibility

Supported Environments

Dev Environment
Client Unsupported
Server Required

About

Project Details

Type
Mod
License
GNU Affero General Public License v3.0 only
Latest Version
1.0.0
Authors

For authors

Embed Badge

If you're the author of this project, you can embed a live badge anywhere that supports HTML or Markdown. It updates automatically whenever ratings change.

Custom banner text
ModDex rating badge preview

Use HTML for any page that supports it, or Markdown for README files and Markdown-based descriptions.

Identifiers

Platform IDs

Modrinth ID

Resources

External Links

Source Issues Wiki Discord

About

Description

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.");
  }
}

Screenshots

Gallery

This project has no gallery images yet.

Versions

Files

Relations

Project Relations

More like this

Similar Mods

Suggestions use data such as tags, dependencies, dependents, descriptions, titles, and more to rank how much they overlap with this mod.

On ModDex

Community snapshot

0
Ratings
0
Followers
0
In stacks

By the numbers

Statistics

~4,000
Downloads
Last Updated
CurseForge
Created
Last synced
When ModDex last fetched this project from CurseForge or Modrinth. Every project is re-checked on a schedule, and any project that ships a new file is synced automatically within hours of the release.
New file updates sync automatically
How syncing works