Skip to content

Commit

Permalink
Fix dimensional train crash
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Oct 20, 2024
1 parent 38420bb commit db8e345
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dev.ithundxr.railwaystweaks.mixin.compat.create;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.simibubi.create.content.trains.entity.Carriage;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Carriage.DimensionalCarriageEntity.class)
public class Carriage$DimensionalCarriageEntityMixin {
@Final
@Shadow(aliases = "this$0")
Carriage this$0;

@Shadow public Vec3 positionAnchor;

@Inject(method = "createEntity", at = @At("HEAD"))
private void railwaysTweaks$fixDimensionalTrainCrash(Level level, boolean loadPassengers, CallbackInfo ci) {
((CarriageAccessor) this$0).railwaysTweaks$getSerializedEntity().put(
"Pos",
railwaysTweaks$newDoubleList(
positionAnchor.x(),
positionAnchor.y(),
positionAnchor.z()
)
);
}

@WrapWithCondition(method = "createEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;moveTo(Lnet/minecraft/world/phys/Vec3;)V"))
private boolean railwaysTweaks$fixDimensionalTrainCrash2(Entity instance, Vec3 vec) {
return false;
}

@Unique
private static ListTag railwaysTweaks$newDoubleList(double... pValues) {
ListTag listtag = new ListTag();

for (double d : pValues)
listtag.add(DoubleTag.valueOf(d));

return listtag;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.ithundxr.railwaystweaks.mixin.compat.create;

import com.simibubi.create.content.trains.entity.Carriage;
import net.minecraft.nbt.CompoundTag;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(Carriage.class)
public interface CarriageAccessor {
@Accessor("serialisedEntity")
CompoundTag railwaysTweaks$getSerializedEntity();
}
2 changes: 2 additions & 0 deletions src/main/resources/railwaystweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"ServerPlayerMixin",
"ServerStatusPacketListenerImplMixin",
"compat.appleskin.SyncHandlerMixin",
"compat.create.Carriage$DimensionalCarriageEntityMixin",
"compat.create.CarriageAccessor",
"compat.dcintegration.DiscordEventListenerMixin",
"compat.tconstruct.SimpleChannelAccessor"
],
Expand Down

0 comments on commit db8e345

Please sign in to comment.