Search in sources :

Example 6 with Polygon

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();
}
Also used : Polygon(org.valkyrienskies.mod.common.collision.Polygon) Nonnull(javax.annotation.Nonnull)

Example 7 with Polygon

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;
}
Also used : IPhysObjectWorld(org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld) World(net.minecraft.world.World) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 8 with Polygon

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;
        }
    }
}
Also used : ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with Polygon

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;
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Polygon(org.valkyrienskies.mod.common.collision.Polygon) ShipPolygon(org.valkyrienskies.mod.common.collision.ShipPolygon) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)

Example 10 with Polygon

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);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Polygon(org.valkyrienskies.mod.common.collision.Polygon)

Aggregations

Polygon (org.valkyrienskies.mod.common.collision.Polygon)12 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 ShipPolygon (org.valkyrienskies.mod.common.collision.ShipPolygon)7 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Vector3d (org.joml.Vector3d)4 ArrayList (java.util.ArrayList)3 IBlockState (net.minecraft.block.state.IBlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 Vec3d (net.minecraft.util.math.Vec3d)2 Triple (org.apache.commons.lang3.tuple.Triple)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 EntityPolygonCollider (org.valkyrienskies.mod.common.collision.EntityPolygonCollider)2 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)2 IPhysObjectWorld (org.valkyrienskies.mod.common.ships.ship_world.IPhysObjectWorld)2 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Entity (net.minecraft.entity.Entity)1 EntityLiving (net.minecraft.entity.EntityLiving)1