Declare copper rails through AstraPlus and simplify train state
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package online.astradev.content.mixin;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
||||
import net.minecraft.world.level.storage.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
@@ -12,33 +13,17 @@ import org.spongepowered.asm.mixin.injection.*;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(AbstractMinecart.class)
|
||||
public abstract class TrainCartMixin implements CartFrame {
|
||||
@Unique private Vec3 astra$front = Vec3.ZERO;
|
||||
public abstract class TrainCartMixin {
|
||||
@Unique private Vec3 astra$beforePlayerPush;
|
||||
|
||||
@Override
|
||||
public Vec3 astracontent$front() {
|
||||
return astra$front;
|
||||
}
|
||||
|
||||
@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);
|
||||
private void astra$save(ValueOutput output, CallbackInfo ci) {
|
||||
CouplingGeometry.save((AbstractMinecart) (Object) this, output);
|
||||
}
|
||||
|
||||
@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;
|
||||
private void astra$read(ValueInput input, CallbackInfo ci) {
|
||||
CouplingGeometry.load((AbstractMinecart) (Object) this, input);
|
||||
}
|
||||
|
||||
@Inject(
|
||||
@@ -47,19 +32,16 @@ public abstract class TrainCartMixin implements CartFrame {
|
||||
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;
|
||||
astra$beforePlayerPush = other instanceof 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);
|
||||
if (astra$beforePlayerPush == null) return;
|
||||
Vec3 impulse = self.getDeltaMovement().subtract(astra$beforePlayerPush);
|
||||
astra$beforePlayerPush = null;
|
||||
if (impulse.horizontalDistanceSqr() > 1e-12) Trains.playerPush(self);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user