Add chain-coupled minecart trains, closed loops and slime buffers
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
import online.astradev.content.train.*;
|
||||
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 {
|
||||
@Unique private Vec3 astra$front=Vec3.ZERO;
|
||||
@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);}
|
||||
@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",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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user