use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method spawnParticle.
/**
* This is easier to have as an overwrite because there's less laggy hackery to be done then :P
*
* @author DaPorkchop_
*/
@Overwrite
public void spawnParticle(int particleID, boolean ignoreRange, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, int... parameters) {
BlockPos pos = new BlockPos(x, y, z);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
if (physicsObject.isPresent()) {
Vector3d newPosVec = new Vector3d(x, y, z);
// RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform,
// newPosVec);
physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transformPosition(newPosVec, TransformType.SUBSPACE_TO_GLOBAL);
x = newPosVec.x;
y = newPosVec.y;
z = newPosVec.z;
}
for (int i = 0; i < this.eventListeners.size(); ++i) {
this.eventListeners.get(i).spawnParticle(particleID, ignoreRange, x, y, z, xSpeed, ySpeed, zSpeed, parameters);
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method preGetCollisionBoxes.
/**
* Used for two purposes. The first, is to prevent the game from freezing by limiting the size of aabb. The second
* is to fix player sneaking on ships.
*/
@Inject(method = "getCollisionBoxes(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/AxisAlignedBB;ZLjava/util/List;)Z", at = @At("HEAD"), cancellable = true)
private void preGetCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb, boolean p_191504_3_, @Nullable List<AxisAlignedBB> outList, CallbackInfoReturnable<Boolean> callbackInfo) {
double deltaX = Math.abs(aabb.maxX - aabb.minX);
double deltaY = Math.abs(aabb.maxY - aabb.minY);
double deltaZ = Math.abs(aabb.maxZ - aabb.minZ);
if (Math.max(deltaX, Math.max(deltaY, deltaZ)) > 99999D) {
System.err.println(entityIn + "\ntried going extremely fast during the collision step");
new Exception().printStackTrace();
callbackInfo.setReturnValue(Boolean.FALSE);
callbackInfo.cancel();
}
// direction, and uses that to determine if can you sneak.
if (entityIn instanceof EntityPlayer && entityIn.isSneaking()) {
// Add at most once ship block AABB that is colliding with the player. This is ONLY to properly allow
// players to sneak while on ships.
List<PhysicsObject> ships = getManager().getPhysObjectsInAABB(aabb);
for (PhysicsObject wrapper : ships) {
Polygon playerInLocal = new Polygon(aabb, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.GLOBAL_TO_SUBSPACE);
AxisAlignedBB bb = playerInLocal.getEnclosedAABB();
if ((bb.maxX - bb.minX) * (bb.maxZ - bb.minZ) > 9898989) {
// This is too big, something went wrong here
System.err.println("Why did transforming a players bounding box result in a giant bounding box?");
System.err.println(bb + "\n" + wrapper.getShipData() + "\n" + entityIn.toString());
new Exception().printStackTrace();
return;
}
List<AxisAlignedBB> collidingBBs = getCollisionBoxes(null, bb);
Polygon entityPoly = new Polygon(aabb.grow(-.2, 0, -.2));
for (AxisAlignedBB inLocal : collidingBBs) {
ShipPolygon poly = new ShipPolygon(inLocal, wrapper.getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL, wrapper.getShipTransformationManager().normals, wrapper);
EntityPolygonCollider collider = new EntityPolygonCollider(entityPoly, poly, poly.normals, new Vector3d());
collider.processData();
if (!collider.arePolygonsSeparated()) {
outList.add(inLocal);
// vanilla sneak code will work correctly.
return;
}
}
}
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityIntrinsic method onEntityPostMove.
/**
* The goal of this injection is to correctly setup {@link IDraggable#getEntityShipMovementData()} for this Entity.
* Specifically this code handles the last ship touched by the entity, as well as how many ticks ago that touch was.
*/
@Inject(method = "move", at = @At("RETURN"))
private void onEntityPostMove(CallbackInfo callbackInfo) {
final EntityShipMovementData oldEntityShipMovementData = thisClassAsDraggable.getEntityShipMovementData();
if (alteredMovement != null) {
// If alteredMovement isn't null then we're touching a ship.
final EntityShipMovementData newEntityShipMovementData = oldEntityShipMovementData.withLastTouchedShip(alteredMovement.shipTouched).withTicksSinceTouchedShip(0).withTicksPartOfGround(0);
thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
EntityCollisionInjector.alterEntityMovementPost(thisClassAsAnEntity, alteredMovement);
} else {
if (this.collided) {
// If we collided and alteredMovement is null, then we're touching the ground.
final int newTicksPartOfGround = oldEntityShipMovementData.getTicksPartOfGround() + 1;
final EntityShipMovementData newEntityShipMovementData = new EntityShipMovementData(null, 0, newTicksPartOfGround, new Vector3d(), 0);
thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
} else {
// If we're not collided and alteredMovement is null, then we're in the air.
final int newTicksPartOfGround;
if (oldEntityShipMovementData.getLastTouchedShip() != null) {
newTicksPartOfGround = 0;
} else {
newTicksPartOfGround = oldEntityShipMovementData.getTicksPartOfGround() + 1;
}
final EntityShipMovementData newEntityShipMovementData = oldEntityShipMovementData.withTicksSinceTouchedShip(oldEntityShipMovementData.getTicksSinceTouchedShip() + 1).withTicksPartOfGround(newTicksPartOfGround);
thisClassAsDraggable.setEntityShipMovementData(newEntityShipMovementData);
}
}
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityMinecart method transformThis.
private void transformThis(Matrix4dc transform) {
Vector3d pos = transform.transformPosition(JOML.convert(self.getPositionVector()));
Vector3d lastPos = transform.transformPosition(new Vector3d(self.lastTickPosX, self.lastTickPosY, self.lastTickPosZ));
self.setPosition(pos.x, pos.y, pos.z);
self.lastTickPosX = lastPos.x;
self.lastTickPosY = lastPos.y;
self.lastTickPosZ = lastPos.z;
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinNetHandlerPlayServer method onSetPlayerLocation.
/**
* Fixes things such that when mods try to teleport players into the ship space, VS will either
* redirect the teleport or block it. Looking at you SimpleTeleporters mod >:/
*/
@Inject(method = "setPlayerLocation(DDDFFLjava/util/Set;)V", at = @At("HEAD"), cancellable = true)
public void onSetPlayerLocation(double x, double y, double z, float yaw, float pitch, Set<SPacketPlayerPosLook.EnumFlags> relativeSet, CallbackInfo callbackInfo) {
if (!redirectingSetPlayerLocation) {
BlockPos pos = new BlockPos(x, y, z);
// If the player is being teleported to ship space then we have to stop it.
if (ShipChunkAllocator.isBlockInShipyard(pos)) {
callbackInfo.cancel();
redirectingSetPlayerLocation = true;
World world = player.getEntityWorld();
Optional<ShipData> ship = ValkyrienUtils.getShipManagingBlock(world, pos);
if (ship.isPresent()) {
Vector3d tpPos = new Vector3d(x, y, z);
ship.get().getShipTransform().transformPosition(tpPos, TransformType.SUBSPACE_TO_GLOBAL);
// Now call this again with the transformed position.
// player.sendMessage(new TextComponentString("Transformed the player tp from <"
// + x + ":" + y + ":" + z + "> to" + tpPos));
thisAsNetHandler.setPlayerLocation(tpPos.x, tpPos.y, tpPos.z, yaw, pitch, relativeSet);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.printf("Player was teleported to %.1f, %.1f, %.1f, redirected to %.1f, %.1f, %.1f\n", x, y, z, tpPos.x, tpPos.y, tpPos.z);
}
} else {
if (VSConfig.showAnnoyingDebugOutput) {
System.out.printf("Player was teleported to %.1f, %.1f, %.1f, cancelling because no ship found\n", x, y, z);
}
player.sendMessage(new TextComponentString("Tried teleporting you to shipyard but there was no ship; teleportation canceled."));
}
redirectingSetPlayerLocation = false;
}
}
}
Aggregations