Search in sources :

Example 1 with IShipPilot

use of org.valkyrienskies.mod.common.piloting.IShipPilot in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinMovementInputFromOptions method preUpdatePlayerMoveState.

@Inject(method = "updatePlayerMoveState", at = @At("HEAD"), cancellable = true)
public void preUpdatePlayerMoveState(CallbackInfo callbackInfo) {
    IShipPilot pilot = (IShipPilot) Minecraft.getMinecraft().player;
    if (pilot != null) {
        ControllerInputType inputTypeEnum = pilot.getControllerInputEnum();
        if (inputTypeEnum != null) {
            if (inputTypeEnum.shouldLockPlayerMovement()) {
                // Then don't let the player move anymore while it's piloting this bastard
                zeroAllPlayerMovements();
                callbackInfo.cancel();
            }
        }
    }
}
Also used : IShipPilot(org.valkyrienskies.mod.common.piloting.IShipPilot) ControllerInputType(org.valkyrienskies.mod.common.piloting.ControllerInputType) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with IShipPilot

use of org.valkyrienskies.mod.common.piloting.IShipPilot in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntityRenderer method orientCamera.

@Inject(method = "orientCamera", at = @At("HEAD"), cancellable = true)
private void orientCamera(float partialTicks, CallbackInfo ci) {
    EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(mc.getRenderViewEntity());
    if (mountData.getMountedShip() == null) {
        // Do nothing. We don't want to mess with camera code unless we have to.
        return;
    } else {
        // Take over the camera orientation entirely. Don't let anything else touch it.
        ci.cancel();
    }
    Entity entity = this.mc.getRenderViewEntity();
    Vector3d eyeVector = new Vector3d(0, entity.getEyeHeight(), 0);
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        eyeVector.y += .7D;
    }
    double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
    double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks;
    double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
    // Probably overkill, but this should 100% fix the crash in issue #78
    if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
        final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
        renderTransform.transformDirection(eyeVector, TransformType.SUBSPACE_TO_GLOBAL);
        Vector3d playerPosition = JOML.convert(mountData.getMountPos());
        renderTransform.transformPosition(playerPosition, TransformType.SUBSPACE_TO_GLOBAL);
        d0 = playerPosition.x;
        d1 = playerPosition.y;
        d2 = playerPosition.z;
    }
    d0 += eyeVector.x;
    d1 += eyeVector.y;
    d2 += eyeVector.z;
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        if (!this.mc.gameSettings.debugCamEnable) {
            // VS code starts here
            if (mountData.isMounted()) {
                Vector3d playerPosInLocal = JOML.convert(mountData.getMountPos());
                playerPosInLocal.sub(.5D, .6875, .5);
                playerPosInLocal.round();
                BlockPos bedPos = new BlockPos(playerPosInLocal.x, playerPosInLocal.y, playerPosInLocal.z);
                IBlockState state = this.mc.world.getBlockState(bedPos);
                Block block = state.getBlock();
                float angleYaw = 0;
                if (block != null && block.isBed(state, entity.world, bedPos, entity)) {
                    angleYaw = block.getBedDirection(state, entity.world, bedPos).getHorizontalIndex() * 90;
                    angleYaw += 180;
                }
                entity.rotationYaw = entity.prevRotationYaw = angleYaw;
                entity.rotationPitch = entity.prevRotationPitch = 0;
            } else {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = this.mc.world.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(this.mc.world, blockpos, iblockstate, entity);
                GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
                GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
            }
        }
    } else if (this.mc.gameSettings.thirdPersonView > 0) {
        double d3 = this.thirdPersonDistancePrev + (4.0F - this.thirdPersonDistancePrev) * partialTicks;
        IShipPilot shipPilot = (IShipPilot) Minecraft.getMinecraft().player;
        if (shipPilot.isPilotingShip()) {
            // TODO: Make this number scale with the Ship
            d3 = 15D;
        }
        if (this.mc.gameSettings.debugCamEnable) {
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
        } else {
            float f1 = entity.rotationYaw;
            float f2 = entity.rotationPitch;
            if (this.mc.gameSettings.thirdPersonView == 2) {
                f2 += 180.0F;
            }
            double d4 = -MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
            double d5 = MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
            double d6 = (-MathHelper.sin(f2 * 0.017453292F)) * d3;
            for (int i = 0; i < 8; ++i) {
                float f3 = (i & 1) * 2 - 1;
                float f4 = (i >> 1 & 1) * 2 - 1;
                float f5 = (i >> 2 & 1) * 2 - 1;
                f3 = f3 * 0.1F;
                f4 = f4 * 0.1F;
                f5 = f5 * 0.1F;
                IShipPilot pilot = (IShipPilot) Minecraft.getMinecraft().player;
                ((IWorldVS) this.mc.world).excludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
                // RayTraceResult raytraceresult = EntityMoveInjectionMethods.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().world, new Vec3d(d0 + f3, d1 + f4, d2 + f5), new Vec3d(d0 - d4 + f3 + f5, d1 - d6 + f4, d2 - d5 + f5), false, false, false, pilot.getPilotedShip());
                RayTraceResult raytraceresult = mc.world.rayTraceBlocks(new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5));
                ((IWorldVS) this.mc.world).unexcludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
                if (raytraceresult != null) {
                    double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
                    if (d7 < d3) {
                        d3 = d7;
                    }
                }
            }
            if (this.mc.gameSettings.thirdPersonView == 2) {
                GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            }
            GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
            GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
        }
    } else {
        GlStateManager.translate(0.0F, 0.0F, 0.05F);
    }
    if (!this.mc.gameSettings.debugCamEnable) {
        float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
        float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
        float roll = 0.0F;
        if (entity instanceof EntityAnimal) {
            EntityAnimal entityanimal = (EntityAnimal) entity;
            yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
        }
        IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(this.mc.world, entity, partialTicks);
        net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(EntityRenderer.class.cast(this), entity, state, partialTicks, yaw, pitch, roll);
        net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
        GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
    }
    if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
        final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
        Quaterniond orientationQuat = renderTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
        Vector3dc radians = orientationQuat.getEulerAnglesXYZ(new Vector3d());
        float moddedPitch = (float) Math.toDegrees(radians.x());
        float moddedYaw = (float) Math.toDegrees(radians.y());
        float moddedRoll = (float) Math.toDegrees(radians.z());
        GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
    }
    GlStateManager.translate(-eyeVector.x, -eyeVector.y, -eyeVector.z);
    d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks + eyeVector.x;
    d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks + eyeVector.y;
    d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks + eyeVector.z;
    this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
Also used : Entity(net.minecraft.entity.Entity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) IBlockState(net.minecraft.block.state.IBlockState) Quaterniond(org.joml.Quaterniond) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Vector3dc(org.joml.Vector3dc) IShipPilot(org.valkyrienskies.mod.common.piloting.IShipPilot) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityRenderer(net.minecraft.client.renderer.EntityRenderer)

Aggregations

IShipPilot (org.valkyrienskies.mod.common.piloting.IShipPilot)2 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityRenderer (net.minecraft.client.renderer.EntityRenderer)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 Quaterniond (org.joml.Quaterniond)1 Vector3d (org.joml.Vector3d)1 Vector3dc (org.joml.Vector3dc)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 ControllerInputType (org.valkyrienskies.mod.common.piloting.ControllerInputType)1 EntityShipMountData (org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData)1 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)1