Search in sources :

Example 6 with EntityShipMountData

use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData 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)

Example 7 with EntityShipMountData

use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntity method getVectorForRotation.

/**
 * This is public in order to fix #437
 *
 * @author asdf
 */
@Overwrite
public final Vec3d getVectorForRotation(float pitch, float yaw) {
    // BEGIN VANILLA CODE
    float f = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI);
    float f1 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI);
    float f2 = -MathHelper.cos(-pitch * 0.017453292F);
    float f3 = MathHelper.sin(-pitch * 0.017453292F);
    Vec3d vanilla = new Vec3d(f1 * f2, f3, f * f2);
    // END VANILLA CODE
    EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(Entity.class.cast(this));
    if (mountData.isMounted()) {
        return mountData.getMountedShip().getShipTransformationManager().getRenderTransform().rotate(vanilla, TransformType.SUBSPACE_TO_GLOBAL);
    } else {
        return vanilla;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) Vec3d(net.minecraft.util.math.Vec3d) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

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