use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class SimpleEMATransformInterpolator method getCurrentAABB.
@Override
@Nonnull
public AxisAlignedBB getCurrentAABB() {
Matrix4dc latestToCurrent = curTickTransform.getSubspaceToGlobal().mul(latestReceivedTransform.getGlobalToSubspace(), new Matrix4d());
Polygon latestBB = new Polygon(latestRecievedAABB, latestToCurrent);
return latestBB.getEnclosedAABB();
}
use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method getEntitiesWithinAABB.
/**
* @author thebest108
*/
@Overwrite
public <T extends Entity> List<T> getEntitiesWithinAABB(Class<? extends T> clazz, AxisAlignedBB aabb, @Nullable Predicate<? super T> filter) {
List<T> toReturn = this.getEntitiesWithinAABBOriginal(clazz, aabb, filter);
BlockPos pos = new BlockPos((aabb.minX + aabb.maxX) / 2D, (aabb.minY + aabb.maxY) / 2D, (aabb.minZ + aabb.maxZ) / 2D);
Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(World.class.cast(this), pos);
if (physicsObject.isPresent()) {
Polygon poly = new Polygon(aabb, physicsObject.get().getShipTransformationManager().getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL);
// .contract(.3D);
aabb = poly.getEnclosedAABB();
toReturn.addAll(this.getEntitiesWithinAABBOriginal(clazz, aabb, filter));
}
return toReturn;
}
use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method postCheckBlockCollision.
/**
* This mixin fixes players getting kicked for flying when they're standing on the ground.
*/
@Inject(method = "checkBlockCollision", at = @At("HEAD"), cancellable = true)
public void postCheckBlockCollision(final AxisAlignedBB axisAlignedBB, final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
// If there wasn't a collision in the world, then check if there is a collision in ships
final List<PhysicsObject> physObjectsInAABB = getManager().getPhysObjectsInAABB(axisAlignedBB);
for (final PhysicsObject physicsObject : physObjectsInAABB) {
final ShipTransform shipTransform = physicsObject.getShipTransform();
final AxisAlignedBB aabbInShipSpace = new Polygon(axisAlignedBB, shipTransform.getGlobalToSubspace()).getEnclosedAABB();
final boolean collisionInShip = this.checkBlockCollision(aabbInShipSpace);
if (collisionInShip) {
callbackInfoReturnable.setReturnValue(true);
return;
}
}
}
use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityCollisionInjector method getLadderCollisions.
/**
* Returns all the possible ladders that the entity could potentially climb with
*/
public static Iterable<Triple<PhysicsObject, BlockPos, IBlockState>> getLadderCollisions(final EntityLivingBase entity, final List<PhysicsObject> collidingShips) {
final boolean isSpectator = entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator();
final World world = entity.getEntityWorld();
final List<Triple<PhysicsObject, BlockPos, IBlockState>> ladderCollisions = new ArrayList<>();
if (!isSpectator) {
final AxisAlignedBB bb = entity.getEntityBoundingBox();
for (PhysicsObject physicsObject : collidingShips) {
final Polygon playerPolyInShip = new Polygon(bb, physicsObject.getShipTransform(), TransformType.GLOBAL_TO_SUBSPACE);
final AxisAlignedBB playerPolyInShipBB = playerPolyInShip.getEnclosedAABB();
int mX = MathHelper.floor(playerPolyInShipBB.minX);
int mY = MathHelper.floor(playerPolyInShipBB.minY);
int mZ = MathHelper.floor(playerPolyInShipBB.minZ);
for (int y2 = mY; (double) y2 < playerPolyInShipBB.maxY; ++y2) {
for (int x2 = mX; (double) x2 < playerPolyInShipBB.maxX; ++x2) {
for (int z2 = mZ; (double) z2 < playerPolyInShipBB.maxZ; ++z2) {
BlockPos tmp = new BlockPos(x2, y2, z2);
IBlockState state = world.getBlockState(tmp);
if (state.getBlock().isLadder(state, world, tmp, entity)) {
ladderCollisions.add(Triple.of(physicsObject, tmp, state));
}
}
}
}
}
}
return ladderCollisions;
}
use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipTransformationManager method updateParentAABB.
// TODO: Use Octrees to optimize this, or more preferably QuickHull3D.
private void updateParentAABB() {
AxisAlignedBB subspaceBB = parent.getBlockPositions().makeAABB();
if (subspaceBB == null) {
// The aabbMaker didn't know what the aabb was, just don't update the aabb for now.
return;
}
// Expand subspaceBB by 1 to fit the block grid.
subspaceBB = subspaceBB.expand(1, 1, 1);
// Now transform the subspaceBB to world coordinates
Polygon largerPoly = new Polygon(subspaceBB, getCurrentTickTransform(), TransformType.SUBSPACE_TO_GLOBAL);
// Set the ship AABB to that of the polygon.
AxisAlignedBB worldBB = largerPoly.getEnclosedAABB();
parent.setShipBoundingBox(worldBB);
}
Aggregations