2026-09-13 09:38:31 +03:00
|
|
|
package online.astradev.content.mixin;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
|
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
|
|
|
|
import net.minecraft.world.level.storage.*;
|
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
2026-09-13 21:55:44 +03:00
|
|
|
|
2026-09-13 09:38:31 +03:00
|
|
|
import online.astradev.content.train.*;
|
2026-09-13 21:55:44 +03:00
|
|
|
|
2026-09-13 09:38:31 +03:00
|
|
|
import org.spongepowered.asm.mixin.*;
|
|
|
|
|
import org.spongepowered.asm.mixin.injection.*;
|
|
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
|
|
|
|
|
|
|
|
@Mixin(AbstractMinecart.class)
|
|
|
|
|
public abstract class TrainCartMixin implements CartFrame {
|
2026-09-13 21:55:44 +03:00
|
|
|
@Unique private Vec3 astra$front = Vec3.ZERO;
|
2026-09-13 10:34:51 +03:00
|
|
|
@Unique private Vec3 astra$beforePlayerPush;
|
2026-09-13 21:55:44 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Vec3 astracontent$front() {
|
|
|
|
|
return astra$front;
|
2026-09-13 09:38:31 +03:00
|
|
|
}
|
2026-09-13 21:55:44 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void astracontent$front(Vec3 axis) {
|
|
|
|
|
astra$front = axis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Inject(method = "addAdditionalSaveData", at = @At("RETURN"))
|
|
|
|
|
private void astra$save(ValueOutput out, CallbackInfo ci) {
|
|
|
|
|
out.putDouble("AstraTrainFrontX", astra$front.x);
|
|
|
|
|
out.putDouble("AstraTrainFrontZ", astra$front.z);
|
2026-09-13 10:34:51 +03:00
|
|
|
}
|
2026-09-13 21:55:44 +03:00
|
|
|
|
|
|
|
|
@Inject(method = "readAdditionalSaveData", at = @At("RETURN"))
|
|
|
|
|
private void astra$read(ValueInput in, CallbackInfo ci) {
|
|
|
|
|
double x = in.getDoubleOr("AstraTrainFrontX", 0), z = in.getDoubleOr("AstraTrainFrontZ", 0);
|
|
|
|
|
astra$front =
|
|
|
|
|
Double.isFinite(x) && Double.isFinite(z)
|
|
|
|
|
? new Vec3(x, 0, z).normalize()
|
|
|
|
|
: Vec3.ZERO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Inject(
|
|
|
|
|
method = "push(Lnet/minecraft/world/entity/Entity;)V",
|
|
|
|
|
at = @At("HEAD"),
|
|
|
|
|
cancellable = true)
|
|
|
|
|
private void astra$noInternalCollision(Entity other, CallbackInfo ci) {
|
|
|
|
|
var self = (AbstractMinecart) (Object) this;
|
|
|
|
|
astra$beforePlayerPush =
|
|
|
|
|
other instanceof net.minecraft.world.entity.player.Player
|
|
|
|
|
? self.getDeltaMovement()
|
|
|
|
|
: null;
|
|
|
|
|
if (other instanceof AbstractMinecart cart && Trains.connected(self, cart)) ci.cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Inject(method = "push(Lnet/minecraft/world/entity/Entity;)V", at = @At("RETURN"))
|
|
|
|
|
private void astra$playerPush(Entity other, CallbackInfo ci) {
|
|
|
|
|
var self = (AbstractMinecart) (Object) this;
|
|
|
|
|
if (astra$beforePlayerPush != null
|
|
|
|
|
&& self.getDeltaMovement().subtract(astra$beforePlayerPush).horizontalDistanceSqr()
|
|
|
|
|
> 1e-12) Trains.playerPush(self);
|
|
|
|
|
astra$beforePlayerPush = null;
|
2026-09-13 09:38:31 +03:00
|
|
|
}
|
|
|
|
|
}
|