Search in sources :

Example 1 with AirshipContraptionEntity

use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.

the class ClientPacketHandler method handlePacket.

public static void handlePacket(AirshipAddSubcontraptionPacket msg, Supplier<NetworkEvent.Context> ctx) {
    Map<Integer, AirshipContraptionEntity> allAirships = AirshipManager.INSTANCE.AllClientAirships;
    if (allAirships.containsKey(msg.plotID)) {
        AirshipContraptionEntity airship = allAirships.get(msg.plotID);
        airship.addSubcontraptionClient(msg.nbt, msg.uuid, msg.pos);
    }
}
Also used : AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)

Example 2 with AirshipContraptionEntity

use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.

the class ServerWorldEventMixin method addFreshEntity.

/**
 * @author RyanHCode
 */
@Overwrite(remap = false)
public boolean addFreshEntity(Entity entity) {
    if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID && !(entity instanceof AbstractContraptionEntity || entity instanceof SuperGlueEntity)) {
        // get position of entity
        Vector3d pos = entity.position();
        BlockPos bPos = entity.blockPosition();
        // get airship plot id
        int id = AirshipManager.getIdFromPlotPos(bPos);
        BlockPos plotPos = AirshipManager.getPlotPosFromId(id);
        // get airship
        AirshipContraptionEntity airship = AirshipManager.INSTANCE.AllAirships.get(id);
        if (airship != null) {
            Vector3d position = pos;
            position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
            position = airship.toGlobalVector(position, 1.0f);
            // rotate entity motion
            entity.setDeltaMovement(airship.applyRotation(entity.getDeltaMovement(), 1.0f));
            entity.setPosRaw(position.x, position.y, position.z);
            entity.setLevel(airship.level);
            return airship.level.addFreshEntity(entity);
        }
    }
    return this.addEntity(entity);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) SuperGlueEntity(com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) AbstractContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with AirshipContraptionEntity

use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.

the class ContraptionColliderMixin method collideEntitiesMixin.

@Redirect(remap = false, method = "collideEntities", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/contraptions/components/structureMovement/ContraptionCollider;getWorldToLocalTranslation(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/vector/Vector3d;Lcom/simibubi/create/foundation/collision/Matrix3d;F)Lnet/minecraft/util/math/vector/Vector3d;"))
private static Vector3d collideEntitiesMixin(Entity entity, Vector3d anchorVec, Matrix3d rotationMatrix, float yawOffset, AbstractContraptionEntity contraptionEntity) {
    Vector3d position = getWorldToLocalTranslation(entity, anchorVec, rotationMatrix, yawOffset);
    if (contraptionEntity instanceof AirshipContraptionEntity) {
        AirshipContraptionEntity airshipEntity = (AirshipContraptionEntity) contraptionEntity;
        position = position.add(airshipEntity.centerOfMassOffset);
    }
    return position;
}
Also used : AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with AirshipContraptionEntity

use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.

the class ContraptionRenderInfoMixin method afterBeginFrame.

// /**
// * @author Eriksonn
// */
// @Overwrite(remap = false)
// public void beginFrame(BeginFrameEvent event) {
// matrices.clear();
// 
// AbstractContraptionEntity entity = contraption.entity;
// if(entity instanceof ControlledContraptionEntity && entity.level.dimension() == AirshipDimensionManager.WORLD_ID) {
// int plotId = AirshipManager.getIdFromPlotPos(entity.blockPosition());
// AirshipContraptionEntity airshipEntity = AirshipManager.INSTANCE.AllAirships.get(plotId);
// if (airshipEntity != null) {
// entity = airshipEntity;
// }
// }
// visible = event.getClippingHelper().isVisible(entity.getBoundingBoxForCulling().inflate(2));
// }
@Inject(locals = LocalCapture.CAPTURE_FAILHARD, remap = false, method = "beginFrame", at = @At("TAIL"))
public void afterBeginFrame(BeginFrameEvent event, CallbackInfo ci, AbstractContraptionEntity entity) {
    if (entity instanceof ControlledContraptionEntity && entity.level instanceof FakeAirshipClientWorld) {
        int plotId = AirshipManager.getIdFromPlotPos(entity.blockPosition());
        AirshipContraptionEntity airshipEntity = AirshipManager.INSTANCE.AllAirships.get(plotId);
        if (airshipEntity != null) {
            visible = event.getClippingHelper().isVisible(airshipEntity.getBoundingBoxForCulling().inflate(2));
        }
    }
// 
}
Also used : AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) FakeAirshipClientWorld(com.eriksonn.createaeronautics.world.FakeAirshipClientWorld) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with AirshipContraptionEntity

use of com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity in project Create_Aeronautics by Eriksonnaren.

the class RedstoneLinkNetworkMixin method updateNetworkOf.

@Inject(method = "updateNetworkOf", remap = false, at = @At("HEAD"))
public void updateNetworkOf(IWorld world, IRedstoneLinkable inRealWorldActor, CallbackInfo ci) {
    // airship dimension trickery
    ServerWorld airshipDimension = AirshipDimensionManager.INSTANCE.getWorld();
    if (world != airshipDimension) {
        // iterate over all airships in the world
        for (AirshipContraptionEntity airship : AirshipManager.INSTANCE.AllAirships.values()) {
            // plotpos
            BlockPos plotPos = airship.getPlotPos();
            // get network
            Set<IRedstoneLinkable> airshipNetwork = Create.REDSTONE_LINK_NETWORK_HANDLER.getNetworkOf(airshipDimension, inRealWorldActor);
            Set<IRedstoneLinkable> realWorldNetwork = Create.REDSTONE_LINK_NETWORK_HANDLER.getNetworkOf(world, inRealWorldActor);
            int power = 0;
            for (Iterator<IRedstoneLinkable> iterator = airshipNetwork.iterator(); iterator.hasNext(); ) {
                IRedstoneLinkable inAirshipDimensionActor = iterator.next();
                if (!inAirshipDimensionActor.isAlive()) {
                    iterator.remove();
                    continue;
                }
                if (!withinRange(inRealWorldActor, airship, plotPos, inAirshipDimensionActor)) {
                    iterator.remove();
                    continue;
                }
                if (power < 15)
                    power = Math.max(inAirshipDimensionActor.getTransmittedStrength(), power);
                for (Iterator<IRedstoneLinkable> iterator1 = realWorldNetwork.iterator(); iterator1.hasNext(); ) {
                    IRedstoneLinkable inRealWorldActor2 = iterator1.next();
                    if (!inRealWorldActor2.isAlive()) {
                        iterator1.remove();
                        continue;
                    }
                    if (!withinRange(inRealWorldActor2, airship, plotPos, inAirshipDimensionActor)) {
                        iterator1.remove();
                        continue;
                    }
                    if (power < 15)
                        power = Math.max(inRealWorldActor2.getTransmittedStrength(), power);
                }
            }
            if (inRealWorldActor instanceof LinkBehaviour) {
                LinkBehaviour linkBehaviour = (LinkBehaviour) inRealWorldActor;
                // fix one-to-one loading order problem
                if (linkBehaviour.isListening()) {
                    linkBehaviour.newPosition = true;
                    linkBehaviour.setReceivedStrength(power);
                }
            }
            for (IRedstoneLinkable other : airshipNetwork) {
                if (other != inRealWorldActor && other.isListening() && withinRange(inRealWorldActor, airship, plotPos, other))
                    other.setReceivedStrength(power);
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) LinkBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) BlockPos(net.minecraft.util.math.BlockPos) IRedstoneLinkable(com.simibubi.create.content.logistics.IRedstoneLinkable) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AirshipContraptionEntity (com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity)14 BlockPos (net.minecraft.util.math.BlockPos)7 Vector3d (net.minecraft.util.math.vector.Vector3d)5 ServerWorld (net.minecraft.world.server.ServerWorld)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 Inject (org.spongepowered.asm.mixin.injection.Inject)3 AirshipContraption (com.eriksonn.createaeronautics.contraptions.AirshipContraption)1 FakeAirshipClientWorld (com.eriksonn.createaeronautics.world.FakeAirshipClientWorld)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 AbstractContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity)1 Contraption (com.simibubi.create.content.contraptions.components.structureMovement.Contraption)1 SuperGlueEntity (com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity)1 IRedstoneLinkable (com.simibubi.create.content.logistics.IRedstoneLinkable)1 LinkBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkBehaviour)1 RaycastHelper (com.simibubi.create.foundation.utility.RaycastHelper)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BlockState (net.minecraft.block.BlockState)1 Minecraft (net.minecraft.client.Minecraft)1 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)1 SPlaySoundEffectPacket (net.minecraft.network.play.server.SPlaySoundEffectPacket)1