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();
}
}
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");
}
}
}
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();
}
}
}
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;
}
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"));
}
Aggregations