Search in sources :

Example 56 with Vector3d

use of org.joml.Vector3d 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 57 with Vector3d

use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinEntityPlayer method preGetBedSpawnLocation.

@Inject(method = "getBedSpawnLocation", at = @At("HEAD"), cancellable = true)
private static void preGetBedSpawnLocation(World worldIn, BlockPos bedLocation, boolean forceSpawn, CallbackInfoReturnable<BlockPos> callbackInfo) {
    Optional<ShipData> shipData = ValkyrienUtils.getQueryableData(worldIn).getShipFromBlock(bedLocation);
    if (shipData.isPresent()) {
        ShipTransform positionData = shipData.get().getShipTransform();
        if (positionData != null) {
            Vector3d bedLocationD = JOML.castDouble(JOML.convert(bedLocation)).add(0.5, 0.5, 0.5);
            positionData.getSubspaceToGlobal().transformPosition(bedLocationD);
            bedLocationD.y += 1D;
            bedLocation = JOML.toMinecraft(JOML.castInt(bedLocationD));
            callbackInfo.setReturnValue(bedLocation);
        } else {
            System.err.println("A ship just had chunks claimed persistent, but not any position data persistent");
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Vector3d(org.joml.Vector3d) ShipData(org.valkyrienskies.mod.common.ships.ShipData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 58 with Vector3d

use of org.joml.Vector3d 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 59 with Vector3d

use of org.joml.Vector3d in project chunkstories-api by Hugobros3.

the class CollisionBox method lineIntersection.

/**
 * Box / Line collision check Returns null if no collision, a Vector3dm if collision, containing the collision point.
 *
 * @return The collision point, or NULL.
 */
public Vector3dc lineIntersection(Vector3dc lineStart, Vector3dc lineDirectionIn) {
    double minDist = 0.0;
    double maxDist = 256d;
    Vector3d min = new Vector3d(xpos, ypos, zpos);
    Vector3d max = new Vector3d(xpos + xw, ypos + h, zpos + zw);
    Vector3d lineDirection = new Vector3d(lineDirectionIn);
    lineDirection.normalize();
    Vector3d invDir = new Vector3d(1f / lineDirection.x(), 1f / lineDirection.y(), 1f / lineDirection.z());
    boolean signDirX = invDir.x() < 0;
    boolean signDirY = invDir.y() < 0;
    boolean signDirZ = invDir.z() < 0;
    Vector3d bbox = signDirX ? max : min;
    double tmin = (bbox.x() - lineStart.x()) * invDir.x();
    bbox = signDirX ? min : max;
    double tmax = (bbox.x() - lineStart.x()) * invDir.x();
    bbox = signDirY ? max : min;
    double tymin = (bbox.y() - lineStart.y()) * invDir.y();
    bbox = signDirY ? min : max;
    double tymax = (bbox.y() - lineStart.y()) * invDir.y();
    if ((tmin > tymax) || (tymin > tmax)) {
        return null;
    }
    if (tymin > tmin) {
        tmin = tymin;
    }
    if (tymax < tmax) {
        tmax = tymax;
    }
    bbox = signDirZ ? max : min;
    double tzmin = (bbox.z() - lineStart.z()) * invDir.z();
    bbox = signDirZ ? min : max;
    double tzmax = (bbox.z() - lineStart.z()) * invDir.z();
    if ((tmin > tzmax) || (tzmin > tmax)) {
        return null;
    }
    if (tzmin > tmin) {
        tmin = tzmin;
    }
    if (tzmax < tmax) {
        tmax = tzmax;
    }
    if ((tmin < maxDist) && (tmax > minDist)) {
        Vector3d intersect = new Vector3d(lineStart);
        intersect.add(lineDirection.mul(tmin));
        return intersect;
    // return Vector3dm.add(lineStart, lineDirection.clone().normalize().scale(tmin), null);
    // return ray.getPointAtDistance(tmin);
    }
    return null;
}
Also used : Vector3d(org.joml.Vector3d)

Example 60 with Vector3d

use of org.joml.Vector3d in project chunkstories-api by Hugobros3.

the class EntityBase method setupCamera.

@Override
public void setupCamera(RenderingInterface renderingInterface) {
    renderingInterface.getCamera().setCameraPosition(new Vector3d(positionComponent.getLocation()));
    // Default FOV
    renderingInterface.getCamera().setFOV((float) renderingInterface.getClient().getConfiguration().getDoubleOption("fov"));
}
Also used : Vector3d(org.joml.Vector3d)

Aggregations

Vector3d (org.joml.Vector3d)117 Vector3dc (org.joml.Vector3dc)33 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)20 BlockPos (net.minecraft.util.math.BlockPos)19 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)18 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)9 ShipData (org.valkyrienskies.mod.common.ships.ShipData)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 IBlockState (net.minecraft.block.state.IBlockState)6 Vec3d (net.minecraft.util.math.Vec3d)6 Vector3f (org.joml.Vector3f)6 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5