Search in sources :

Example 6 with IBlockCacheNode

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

the class BlockProperties method isPassableRay.

/**
 * Checks if is passable ray.
 *
 * @param access
 *            the access
 * @param blockX
 *            Block location.
 * @param blockY
 *            the block y
 * @param blockZ
 *            the block z
 * @param oX
 *            Origin / offset from block location.
 * @param oY
 *            the o y
 * @param oZ
 *            the o z
 * @param dX
 *            Direction (multiplied by dT to get end point of move).
 * @param dY
 *            the d y
 * @param dZ
 *            the d z
 * @param dT
 *            the d t
 * @return true, if is passable ray
 */
public static final boolean isPassableRay(final BlockCache access, final int blockX, final int blockY, final int blockZ, final double oX, final double oY, final double oZ, final double dX, final double dY, final double dZ, final double dT) {
    // TODO: Method signature with node, nodeAbove.
    final IBlockCacheNode node = access.getOrCreateBlockCacheNode(blockX, blockY, blockZ, false);
    if (BlockProperties.isPassable(node.getType())) {
        return true;
    }
    double[] bounds = access.getBounds(blockX, blockY, blockZ);
    if (bounds == null) {
        return true;
    }
    // Simplified check: Only collision of bounds of the full move is checked.
    final double minX, maxX;
    if (dX < 0.0) {
        minX = dX * dT + oX + blockX;
        maxX = oX + blockX;
    } else {
        maxX = dX * dT + oX + blockX;
        minX = oX + blockX;
    }
    final double minY, maxY;
    if (dY < 0.0) {
        minY = dY * dT + oY + blockY;
        maxY = oY + blockY;
    } else {
        maxY = dY * dT + oY + blockY;
        minY = oY + blockY;
    }
    final double minZ, maxZ;
    if (dZ < 0.0) {
        minZ = dZ * dT + oZ + blockZ;
        maxZ = oZ + blockZ;
    } else {
        maxZ = dZ * dT + oZ + blockZ;
        minZ = oZ + blockZ;
    }
    if (!collidesBlock(access, minX, minY, minZ, maxX, maxY, maxZ, blockX, blockY, blockZ, node, null, getBlockFlags(node.getType()) | F_COLLIDE_EDGES)) {
        // TODO: Might check for fence too, here.
        return true;
    }
    // TODO: check f_itchy once exists.
    if (BlockProperties.isPassableWorkaround(access, blockX, blockY, blockZ, oX, oY, oZ, node, dX, dY, dZ, dT)) {
        return true;
    }
    // (Could allow start-end if passable + check first collision time or some estimate.)
    return false;
}
Also used : IBlockCacheNode(fr.neatmonster.nocheatplus.utilities.map.BlockCache.IBlockCacheNode)

Example 7 with IBlockCacheNode

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

the class DebugUtil method addBlockInfo.

/**
 * Add information about id, data, shape to the builder. Starts with a space
 * always.
 *
 * @param builder
 * @param blockCache
 * @param x
 *            Block coordinates.
 * @param y
 * @param z
 * @param messagePrefix
 *            May be null.
 */
public static void addBlockInfo(final StringBuilder builder, final BlockCache blockCache, final int x, final int y, final int z, final String messagePrefix) {
    if (messagePrefix != null && !messagePrefix.isEmpty()) {
        builder.append(messagePrefix);
    }
    builder.append(" id=");
    final IBlockCacheNode node = blockCache.getOrCreateBlockCacheNode(x, y, z, true);
    final Material id = node.getType();
    builder.append(id);
    builder.append(" data=");
    builder.append(node.getData());
    final double[] bounds = node.getBounds();
    if (bounds != null) {
        final double minHeight = BlockProperties.getGroundMinHeight(blockCache, x, y, z, node, BlockProperties.getBlockFlags(id));
        builder.append(" shape=[");
        builder.append(bounds[0]);
        builder.append(", ");
        builder.append(bounds[1]);
        builder.append(", ");
        builder.append(bounds[2]);
        builder.append(", ");
        builder.append(bounds[3]);
        builder.append(", ");
        builder.append(minHeight == bounds[4] ? minHeight : (minHeight + ".." + bounds[4]));
        builder.append(", ");
        builder.append(bounds[5]);
        builder.append("]");
    }
}
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