org.bukkit.FluidCollisionMode Java Examples

The following examples show how to use org.bukkit.FluidCollisionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VectorUtils.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get to know where the {@link Vector} intersects with a {@link org.bukkit.block.Block}.
 * Non-Occluding {@link Block}s as defined in {@link BlockUtils#isReallyOccluding(Material)} are ignored.
 *
 * @param start     the starting {@link Location}
 * @param direction the {@link Vector} which should be checked
 *
 * @return The length when the {@link Vector} intersects or 0 if no intersection was found
 */
public static double getDistanceToFirstIntersectionWithBlock(final Location start, final Vector direction)
{
    final int length = (int) Math.floor(direction.length());
    Preconditions.checkNotNull(start.getWorld(), "RayTrace: Unknown start world.");

    if (length >= 1) {
        if (RAY_TRACING) {
            RayTraceResult result = start.getWorld().rayTraceBlocks(start, direction, length, FluidCollisionMode.NEVER, true);
            // Hit nothing or the other player
            if (result == null || result.getHitBlock() == null) {
                return 0;
            }

            return start.toVector().distance(result.getHitPosition());
        } else {
            try {
                final BlockIterator blockIterator = new BlockIterator(start.getWorld(), start.toVector(), direction, 0, length);
                Block block;
                while (blockIterator.hasNext()) {
                    block = blockIterator.next();
                    // Account for a Spigot bug: BARRIER and MOB_SPAWNER are not occluding blocks
                    if (BlockUtils.isReallyOccluding(block.getType())) {
                        // Use the middle location of the Block instead of the simple location.
                        return block.getLocation().clone().add(0.5, 0.5, 0.5).distance(start);
                    }
                }
            } catch (IllegalStateException exception) {
                // Just in case the start block could not be found for some reason or a chunk is loaded async.
                return 0;
            }
        }
    }
    return 0;
}
 
Example #2
Source File: EntityBlock.java    From Modern-LWC with MIT License 4 votes vote down vote up
@Override
public RayTraceResult rayTrace(Location location, Vector vector, double v, FluidCollisionMode fluidCollisionMode) {
    return null;
}
 
Example #3
Source File: BlockImpl.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RayTraceResult rayTrace(Location location, Vector vector, double v, FluidCollisionMode fluidCollisionMode) {
    return null;
}
 
Example #4
Source File: DelayedChangeBlock.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) {
	return b.rayTrace(start, direction, maxDistance, fluidCollisionMode);
}
 
Example #5
Source File: BlockStateBlock.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Nullable
@Override
public RayTraceResult rayTrace(Location start, Vector direction, double maxDistance, FluidCollisionMode fluidCollisionMode) {
	return state.getBlock().rayTrace(start, direction, maxDistance, fluidCollisionMode);
}