Search in sources :

Example 1 with IBlockCacheNode

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method collidesBlock.

/**
 * Check if the given bounding box collides with a block of the given id,
 * taking into account the actual bounds of the block.
 *
 * @param access
 *            the access
 * @param minX
 *            the min x
 * @param minY
 *            the min y
 * @param minZ
 *            the min z
 * @param maxX
 *            the max x
 * @param maxY
 *            the max y
 * @param maxZ
 *            the max z
 * @param id
 *            the id
 * @return true, if successful
 */
public static final boolean collidesBlock(final BlockCache access, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final Material id) {
    final int iMinX = Location.locToBlock(minX);
    final int iMaxX = Location.locToBlock(maxX);
    final int iMinY = Location.locToBlock(minY - ((getBlockFlags(id) & F_HEIGHT150) != 0 ? 0.5625 : 0));
    final int iMaxY = Math.min(Location.locToBlock(maxY), access.getMaxBlockY());
    final int iMinZ = Location.locToBlock(minZ);
    final int iMaxZ = Location.locToBlock(maxZ);
    final long flags = getBlockFlags(id);
    for (int x = iMinX; x <= iMaxX; x++) {
        for (int z = iMinZ; z <= iMaxZ; z++) {
            IBlockCacheNode nodeAbove = null;
            for (int y = iMaxY; y >= iMinY; y--) {
                final IBlockCacheNode node = access.getOrCreateBlockCacheNode(x, y, z, false);
                if (id == node.getType()) {
                    if (node.hasNonNullBounds().decideOptimistically()) {
                        if (collidesBlock(access, minX, minY, minZ, maxX, maxY, maxZ, x, y, z, node, nodeAbove, flags)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode)

Example 2 with IBlockCacheNode

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isPassableBox.

/**
 * Check passability with an arbitrary bounding box vs. a block.
 *
 * @param access
 *            the access
 * @param blockX
 *            the block x
 * @param blockY
 *            the block y
 * @param blockZ
 *            the block z
 * @param minX
 *            the min x
 * @param minY
 *            the min y
 * @param minZ
 *            the min z
 * @param maxX
 *            the max x
 * @param maxY
 *            the max y
 * @param maxZ
 *            the max z
 * @return true, if is passable box
 */
public static final boolean isPassableBox(final BlockCache access, final int blockX, final int blockY, final int blockZ, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
    // TODO: This mostly is copy and paste from isPassableRay.
    final IBlockCacheNode node = access.getOrCreateBlockCacheNode(blockX, blockY, blockZ, false);
    final Material id = node.getType();
    if (BlockProperties.isPassable(id)) {
        return true;
    }
    double[] bounds = access.getBounds(blockX, blockY, blockZ);
    if (bounds == null) {
        return true;
    }
    // (Coordinates are already passed in an ordered form.)
    if (!collidesBlock(access, minX, minY, minZ, maxX, maxY, maxZ, blockX, blockY, blockZ, node, null, getBlockFlags(id) | F_COLLIDE_EDGES)) {
        return true;
    }
    // TODO: check f_itchy once exists.
    if (BlockProperties.isPassableWorkaround(access, blockX, blockY, blockZ, minX - blockX, minY - blockY, minZ - blockZ, node, maxX - minX, maxY - minY, maxZ - minZ, 1.0)) {
        return true;
    }
    // Does collide (most likely).
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode) Material(org.bukkit.Material)

Example 3 with IBlockCacheNode

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isOnGround.

/**
 * Similar to collides(... , F_GROUND), but also checks the block above
 * (against spider).<br>
 * NOTE: This does not return true if stuck, to check for that use
 * collidesBlock for the players location.
 *
 * @param access
 *            the access
 * @param minX
 *            Bounding box coordinates...
 * @param minY
 *            the min y
 * @param minZ
 *            the min z
 * @param maxX
 *            the max x
 * @param maxY
 *            Meant to be the foot-level.
 * @param maxZ
 *            the max z
 * @param ignoreFlags
 *            Blocks with these flags are not counted as ground.
 * @return true, if is on ground
 */
public static final boolean isOnGround(final BlockCache access, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long ignoreFlags) {
    final int maxBlockY = access.getMaxBlockY();
    final int iMinX = Location.locToBlock(minX);
    final int iMaxX = Location.locToBlock(maxX);
    final int iMinY = Location.locToBlock(minY - 0.5626);
    if (iMinY > maxBlockY) {
        return false;
    }
    final int iMaxY = Math.min(Location.locToBlock(maxY), maxBlockY);
    final int iMinZ = Location.locToBlock(minZ);
    final int iMaxZ = Location.locToBlock(maxZ);
    for (int x = iMinX; x <= iMaxX; x++) {
        for (int z = iMinZ; z <= iMaxZ; z++) {
            // (Lazy fetch/update only.)
            IBlockCacheNode nodeAbove = null;
            for (int y = iMaxY; y >= iMinY; y--) {
                final IBlockCacheNode node = access.getOrCreateBlockCacheNode(x, y, z, false);
                switch(isOnGround(access, minX, minY, minZ, maxX, maxY, maxZ, ignoreFlags, x, y, z, node, nodeAbove)) {
                    case YES:
                        return true;
                    case MAYBE:
                        nodeAbove = node;
                        continue;
                    case NO:
                        break;
                }
                // case NO
                break;
            }
        }
    }
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode)

Example 4 with IBlockCacheNode

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method isPassableH150.

/**
 * Checking the block below to account for fences and such. This must be
 * called extra to isPassable(...).
 *
 * @param access
 *            the access
 * @param x
 *            the x
 * @param y
 *            the y
 * @param z
 *            the z
 * @return true, if is passable h150
 */
public static final boolean isPassableH150(final BlockCache access, final double x, final double y, final double z) {
    // Check for fences.
    final int by = Location.locToBlock(y) - 1;
    final double fy = y - by;
    if (fy >= 1.5) {
        return true;
    }
    final int bx = Location.locToBlock(x);
    final int bz = Location.locToBlock(z);
    final IBlockCacheNode nodeBelow = access.getOrCreateBlockCacheNode(x, y, z, false);
    final Material belowId = nodeBelow.getType();
    final long belowFlags = getBlockFlags(belowId);
    if ((belowFlags & F_HEIGHT150) == 0 || isPassable(belowId)) {
        return true;
    }
    final double[] belowBounds = nodeBelow.getBounds(access, bx, by, bz);
    if (belowBounds == null) {
        return true;
    }
    if (!collidesBlock(access, x, y, z, x, y, z, bx, by, bz, nodeBelow, null, belowFlags)) {
        return true;
    }
    final double fx = x - bx;
    final double fz = z - bz;
    return isPassableWorkaround(access, bx, by, bz, fx, fy, fz, nodeBelow, 0, 0, 0, 0);
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode) Material(org.bukkit.Material)

Example 5 with IBlockCacheNode

use of fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode in project NoCheatPlus by NoCheatPlus.

the class BlockProperties method collides.

/**
 * Test if the box collide with any block that matches the flags somehow.
 *
 * @param access
 *            the access
 * @param minX
 *            the min x
 * @param minY
 *            the min y
 * @param minZ
 *            the min z
 * @param maxX
 *            the max x
 * @param maxY
 *            the max y
 * @param maxZ
 *            the max z
 * @param flags
 *            The flags to match.
 * @return true, if successful
 */
public static final boolean collides(final BlockCache access, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ, final long flags) {
    final int iMinX = Location.locToBlock(minX);
    final int iMaxX = Location.locToBlock(maxX);
    // At least find fences etc. if searched for.
    // TODO: F_HEIGHT150 could also be ground etc., more consequent might be to always use or flag it.
    final int iMinY = Location.locToBlock(minY - ((flags & F_HEIGHT150) != 0 ? 0.5625 : 0));
    final int iMaxY = Math.min(Location.locToBlock(maxY), access.getMaxBlockY());
    final int iMinZ = Location.locToBlock(minZ);
    final int iMaxZ = Location.locToBlock(maxZ);
    for (int x = iMinX; x <= iMaxX; x++) {
        for (int z = iMinZ; z <= iMaxZ; z++) {
            IBlockCacheNode nodeAbove = null;
            for (int y = iMaxY; y >= iMinY; y--) {
                final IBlockCacheNode node = access.getOrCreateBlockCacheNode(x, y, z, false);
                final Material id = node.getType();
                final long cFlags = getBlockFlags(id);
                if ((cFlags & flags) != 0) {
                    // Might collide.
                    if (node.hasNonNullBounds().decideOptimistically() && collidesBlock(access, minX, minY, minZ, maxX, maxY, maxZ, x, y, z, node, nodeAbove, cFlags)) {
                        return true;
                    }
                }
                nodeAbove = node;
            }
        }
    }
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode) Material(org.bukkit.Material)

Aggregations

IBlockCacheNode (fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode)7 Material (org.bukkit.Material)4