Search in sources :

Example 1 with EntityShipMountData

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

the class ValkyrienUtils method getMountedShipAndPos.

public EntityShipMountData getMountedShipAndPos(Entity entity) {
    Entity ridingEntity = entity.ridingEntity;
    if (ridingEntity instanceof EntityMountable) {
        EntityMountable mountable = (EntityMountable) ridingEntity;
        Optional<PhysicsObject> mountedShip = mountable.getMountedShip();
        if (mountedShip.isPresent()) {
            return new EntityShipMountData(mountedShip.get(), mountable.getMountPos());
        }
    }
    return new EntityShipMountData();
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) EntityMountable(org.valkyrienskies.mod.common.entity.EntityMountable) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 2 with EntityShipMountData

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

the class MixinEntity method getLook.

/**
 * This is easier to have as an overwrite because there's less laggy hackery to be done then :P
 *
 * @author DaPorkchop_
 */
@Overwrite
public Vec3d getLook(float partialTicks) {
    // BEGIN VANILLA CODE
    Vec3d original;
    if (partialTicks == 1.0F) {
        original = this.getVectorForRotation(this.rotationPitch, this.rotationYaw);
    } else {
        float f = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * partialTicks;
        float f1 = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * partialTicks;
        original = this.getVectorForRotation(f, f1);
    }
    // END VANILLA CODE
    EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(Entity.class.cast(this));
    if (mountData.isMounted()) {
        return mountData.getMountedShip().getShipTransformationManager().getRenderTransform().rotate(original, TransformType.SUBSPACE_TO_GLOBAL);
    } else {
        return original;
    }
}
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)

Example 3 with EntityShipMountData

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

the class MixinEntity method getPositionEyesInject.

@Inject(method = "getPositionEyes(F)Lnet/minecraft/util/math/Vec3d;", at = @At("HEAD"), cancellable = true)
private void getPositionEyesInject(float partialTicks, CallbackInfoReturnable<Vec3d> callbackInfo) {
    EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(Entity.class.cast(this));
    if (mountData.isMounted()) {
        Vector3d playerPosition = JOML.convert(mountData.getMountPos());
        mountData.getMountedShip().getShipTransformationManager().getRenderTransform().transformPosition(playerPosition, TransformType.SUBSPACE_TO_GLOBAL);
        Vector3d playerEyes = new Vector3d(0, this.getEyeHeight(), 0);
        // Remove the original position added for the player's eyes
        // RotationMatrices.doRotationOnly(wrapper.wrapping.coordTransform.lToWTransform,
        // playerEyes);
        mountData.getMountedShip().getShipTransformationManager().getCurrentTickTransform().transformDirection(playerEyes, TransformType.SUBSPACE_TO_GLOBAL);
        // Add the new rotate player eyes to the position
        playerPosition.add(playerEyes);
        callbackInfo.setReturnValue(JOML.toMinecraft(playerPosition));
        // return the value, as opposed to the default one
        callbackInfo.cancel();
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) Vector3d(org.joml.Vector3d) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with EntityShipMountData

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

the class MixinRenderManager method preDoRenderEntity.

@Inject(method = "renderEntity", at = @At("HEAD"), cancellable = true)
public void preDoRenderEntity(Entity entityIn, double x, double y, double z, float yaw, float partialTicks, boolean p_188391_10_, CallbackInfo callbackInfo) {
    if (!hasChanged) {
        EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(entityIn);
        if (mountData.isMounted()) {
            double oldPosX = entityIn.posX;
            double oldPosY = entityIn.posY;
            double oldPosZ = entityIn.posZ;
            double oldLastPosX = entityIn.lastTickPosX;
            double oldLastPosY = entityIn.lastTickPosY;
            double oldLastPosZ = entityIn.lastTickPosZ;
            Vec3d mountPos = mountData.getMountPos();
            mountData.getMountedShip().getShipRenderer().applyRenderTransform(partialTicks);
            if (mountPos != null) {
                Vector3d localPosition = JOML.convert(mountPos);
                localPosition.x -= mountData.getMountedShip().getShipRenderer().offsetPos.getX();
                localPosition.y -= mountData.getMountedShip().getShipRenderer().offsetPos.getY();
                localPosition.z -= mountData.getMountedShip().getShipRenderer().offsetPos.getZ();
                x = entityIn.posX = entityIn.lastTickPosX = localPosition.x;
                y = entityIn.posY = entityIn.lastTickPosY = localPosition.y;
                z = entityIn.posZ = entityIn.lastTickPosZ = localPosition.z;
            }
            hasChanged = true;
            this.renderEntity(entityIn, x, y, z, yaw, partialTicks, p_188391_10_);
            hasChanged = false;
            if (mountPos != null) {
                mountData.getMountedShip().getShipRenderer().applyInverseTransform(partialTicks);
            }
            entityIn.posX = oldPosX;
            entityIn.posY = oldPosY;
            entityIn.posZ = oldPosZ;
            entityIn.lastTickPosX = oldLastPosX;
            entityIn.lastTickPosY = oldLastPosY;
            entityIn.lastTickPosZ = oldLastPosZ;
            callbackInfo.cancel();
        }
    }
}
Also used : EntityShipMountData(org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData) Vector3d(org.joml.Vector3d) Vec3d(net.minecraft.util.math.Vec3d) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with EntityShipMountData

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

the class MixinEntityPlayerSP method getLook.

/**
 * @author Tri0de
 * @reason Fixes player ray tracing when they're on a ship thats rotating.
 */
@Overwrite
public Vec3d getLook(final float partialTicks) {
    final Vec3d playerLook;
    if (partialTicks == 1.0F) {
        playerLook = getVectorForRotationInMc_1_12(player.rotationPitch, player.rotationYawHead);
    } else {
        final float playerPitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
        final float playerYaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
        playerLook = this.getVectorForRotationInMc_1_12(playerPitch, playerYaw);
    }
    // If the player is mounted to a ship then we must rotate the player look vector.
    final EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(player);
    if (mountData.isMounted()) {
        return mountData.getMountedShip().getShipTransformationManager().getRenderTransform().rotate(playerLook, TransformType.SUBSPACE_TO_GLOBAL);
    } else {
        return playerLook;
    }
}
Also used : 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