Fix player control of coupled carts and copper rail slope overlays

This commit is contained in:
2026-09-13 10:34:51 +03:00
parent a1802eb02d
commit c39e91d836
10 changed files with 164 additions and 13 deletions
@@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(AbstractMinecart.class)
public abstract class TrainCartMixin implements CartFrame {
@Unique private Vec3 astra$front=Vec3.ZERO;
@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"))
@@ -21,8 +22,17 @@ public abstract class TrainCartMixin implements CartFrame {
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",at=@At("HEAD"),cancellable=true)
@Inject(method="push(Lnet/minecraft/world/entity/Entity;)V",at=@At("HEAD"),cancellable=true)
private void astra$noInternalCollision(Entity other,CallbackInfo ci){
if(other instanceof AbstractMinecart cart && Trains.connected((AbstractMinecart)(Object)this,cart))ci.cancel();
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;
}
}