Search in sources :

Example 6 with AirshipContraptionEntity

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

the class ServerWorldEventMixin method playSound.

/**
 * @author RyanHCode
 */
@Overwrite(remap = false)
public void playSound(@Nullable PlayerEntity pPlayer, double pX, double pY, double pZ, SoundEvent pSound, SoundCategory pCategory, float pVolume, float pPitch) {
    if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID) {
        // get position of entity
        Vector3d pos = new Vector3d(pX, pY, pZ);
        BlockPos bPos = new BlockPos(pos);
        // 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 = new Vector3d(bPos.getX(), bPos.getY(), bPos.getZ());
            position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
            position = airship.toGlobalVector(position, 1.0f);
            airship.level.playSound(pPlayer, position.x, position.y, position.z, pSound, pCategory, pVolume, pPitch);
            return;
        }
    }
    net.minecraftforge.event.entity.PlaySoundAtEntityEvent event = net.minecraftforge.event.ForgeEventFactory.onPlaySoundAtEntity(pPlayer, pSound, pCategory, pVolume, pPitch);
    if (event.isCanceled() || event.getSound() == null)
        return;
    pSound = event.getSound();
    pCategory = event.getCategory();
    pVolume = event.getVolume();
    server.getPlayerList().broadcast(pPlayer, pX, pY, pZ, pVolume > 1.0F ? (double) (16.0F * pVolume) : 16.0D, ((ServerWorld) (Object) this).dimension(), new SPlaySoundEffectPacket(pSound, pCategory, pX, pY, pZ, pVolume, pPitch));
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) SPlaySoundEffectPacket(net.minecraft.network.play.server.SPlaySoundEffectPacket) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 7 with AirshipContraptionEntity

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

the class ServerWorldEventMixin method sendParticles.

/**
 * @author RyanHCode
 */
@Overwrite(remap = false)
private boolean sendParticles(ServerPlayerEntity pPlayer, boolean pLongDistance, double pPosX, double pPosY, double pPosZ, IPacket<?> pPacket) {
    if (pPlayer.getLevel() != ((ServerWorld) (Object) this)) {
        if (((Object) this) instanceof ServerWorld && ((ServerWorld) (Object) this).dimension() == AirshipDimensionManager.WORLD_ID) {
            // get position of entity
            Vector3d pos = new Vector3d(pPosX, pPosY, pPosZ);
            BlockPos bPos = new BlockPos(pos);
            // 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 = new Vector3d(bPos.getX(), bPos.getY(), bPos.getZ());
                position = position.subtract(plotPos.getX(), plotPos.getY(), plotPos.getZ());
                position = airship.toGlobalVector(position, 1.0f);
                BlockPos blockpos = pPlayer.blockPosition();
                SSpawnParticlePacket newPacket = null;
                if (pPacket instanceof SSpawnParticlePacket) {
                    SSpawnParticlePacket spawnPacket = (SSpawnParticlePacket) pPacket;
                    newPacket = new SSpawnParticlePacket(spawnPacket.getParticle(), pLongDistance, position.x, position.y, position.z, spawnPacket.getXDist(), spawnPacket.getYDist(), spawnPacket.getZDist(), spawnPacket.getMaxSpeed(), spawnPacket.getCount());
                }
                if (blockpos.closerThan(position, pLongDistance ? 512.0D : 32.0D)) {
                    pPlayer.connection.send(newPacket != null ? newPacket : pPacket);
                    return true;
                } else {
                    return false;
                }
            }
        }
        return false;
    } else {
        BlockPos blockpos = pPlayer.blockPosition();
        if (blockpos.closerThan(new Vector3d(pPosX, pPosY, pPosZ), pLongDistance ? 512.0D : 32.0D)) {
            pPlayer.connection.send(pPacket);
            return true;
        } else {
            return false;
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) SSpawnParticlePacket(net.minecraft.network.play.server.SSpawnParticlePacket) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with AirshipContraptionEntity

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

the class RenderEvents method renderList.

/**
 * Renders block outline for contraptions
 */
/*public static void drawLine(VertexConsumer consumer, Matrix4f matrix, Vector3d vecA, Vector3d vecB, Vector3d normal, int r, int g, int b, int a)
    {
        consumer.vertex(matrix, (float)vecA.x, (float)vecA.y, (float)vecA.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
        consumer.vertex(matrix, (float)vecB.x, (float)vecB.y, (float)vecB.z).color(r, g, b, a).normal((float) normal.x, (float) normal.y, (float) normal.z).endVertex();
    }*/
@SubscribeEvent
public static void renderList(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getInstance();
    mc.getProfiler().push("renderVehicleDebug");
    ClientPlayerEntity player = mc.player;
    if (player == null)
        return;
    Vector3d origin = RaycastHelper.getTraceOrigin(mc.player);
    double reach = mc.gameMode.getPickRange();
    if (mc.hitResult != null && mc.hitResult.getLocation() != null)
        reach = Math.max(mc.hitResult.getLocation().distanceTo(origin), reach);
    Vector3d target = RaycastHelper.getTraceTarget(mc.player, reach, origin);
    for (AirshipContraptionEntity contraptionEntity : mc.level.getEntitiesOfClass(AirshipContraptionEntity.class, new AxisAlignedBB(origin, target))) {
        Vector3d localOrigin = contraptionEntity.toLocalVector(origin, 1);
        Vector3d localTarget = contraptionEntity.toLocalVector(target, 1);
        Contraption contraption = contraptionEntity.getContraption();
        MutableObject<BlockRayTraceResult> mutableResult = new MutableObject<>();
        AtomicReference<VoxelShape> voxelShape = new AtomicReference();
        RaycastHelper.PredicateTraceResult predicateResult = RaycastHelper.rayTraceUntil(localOrigin, localTarget, p -> {
            Template.BlockInfo blockInfo = contraption.getBlocks().get(p);
            if (blockInfo == null)
                return false;
            BlockState state = blockInfo.state;
            VoxelShape raytraceShape = state.getShape(Minecraft.getInstance().level, BlockPos.ZERO.below());
            if (raytraceShape.isEmpty())
                return false;
            BlockRayTraceResult rayTrace = raytraceShape.clip(localOrigin, localTarget, p);
            if (rayTrace != null) {
                mutableResult.setValue(rayTrace);
                voxelShape.set(raytraceShape);
                return true;
            }
            return false;
        });
        if (predicateResult == null || predicateResult.missed())
            return;
        BlockRayTraceResult rayTraceResult = mutableResult.getValue();
        BlockPos blockPos = rayTraceResult.getBlockPos();
        renderBlockOutline(contraptionEntity, event.getMatrixStack(), voxelShape.get(), blockPos, event.getPartialTicks());
    }
    mc.getProfiler().pop();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) AtomicReference(java.util.concurrent.atomic.AtomicReference) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Contraption(com.simibubi.create.content.contraptions.components.structureMovement.Contraption) Minecraft(net.minecraft.client.Minecraft) Template(net.minecraft.world.gen.feature.template.Template) AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) RaycastHelper(com.simibubi.create.foundation.utility.RaycastHelper) BlockPos(net.minecraft.util.math.BlockPos) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) MutableObject(org.apache.commons.lang3.mutable.MutableObject) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 9 with AirshipContraptionEntity

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

the class ContraptionRenderInfoMixin method onSetupMatrices.

@Inject(locals = LocalCapture.CAPTURE_FAILHARD, remap = false, method = "setupMatrices", at = @At(remap = false, value = "INVOKE", target = "Lcom/mojang/blaze3d/matrix/MatrixStack;translate(DDD)V"))
public void onSetupMatrices(MatrixStack viewProjection, double camX, double camY, double camZ, CallbackInfo ci, AbstractContraptionEntity entity, double x, double y, double z) {
    if (entity instanceof ControlledContraptionEntity && entity.level.dimension() == AirshipDimensionManager.WORLD_ID) {
        int plotId = AirshipManager.getIdFromPlotPos(entity.blockPosition());
        AirshipContraptionEntity airshipEntity = AirshipManager.INSTANCE.AllAirships.get(plotId);
        BlockPos anchorPos = AirshipManager.getPlotPosFromId(plotId);
    // viewProjection.popPose();
    // viewProjection.pushPose();
    // Vector3d v = airshipEntity .position().add(entity.position()).subtract(new Vector3d(anchorPos.getX(),anchorPos.getY(),anchorPos.getZ()));
    // viewProjection.translate(v.x-camX,v.y-camY,v.z-camZ);
    // x=v.x-camX;
    }
}
Also used : AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) BlockPos(net.minecraft.util.math.BlockPos) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with AirshipContraptionEntity

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

the class ContraptionRenderMixin method renderTileEntities.

/**
 * @author Eriksonn
 */
@Overwrite(remap = false)
public static void renderTileEntities(World world, PlacementSimulationWorld renderWorld, Contraption c, ContraptionMatrices matrices, IRenderTypeBuffer buffer) {
    MatrixStack ms = matrices.getModelViewProjection();
    if (c instanceof AirshipContraption) {
        int plotId = ((AirshipContraptionEntity) c.entity).plotId;
        BlockPos anchorPos = AirshipManager.getPlotPosFromId(plotId);
        ms.translate(0, -anchorPos.getY(), 0);
    }
    // if(world.dimension() == AirshipDimensionManager.WORLD_ID)
    // {
    // int plotId = AirshipManager.getIdFromPlotPos(c.anchor);
    // AirshipContraptionEntity entity = AirshipManager.INSTANCE.AllAirships.get(plotId);
    // }
    TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, ms, matrices.getLight(), buffer);
}
Also used : AirshipContraptionEntity(com.eriksonn.createaeronautics.contraptions.AirshipContraptionEntity) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) AirshipContraption(com.eriksonn.createaeronautics.contraptions.AirshipContraption) BlockPos(net.minecraft.util.math.BlockPos) Overwrite(org.spongepowered.asm.mixin.Overwrite)

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