Add a filter block

Could it be possible to add a filter that will detect the first block
the BlockRay hit. The filter should detect if it hit the torch, snow
layer, slab, etc or if it hit the air of the block(Example: Around the

        Player player = event.getCause().first(Player.class).get();
        BlockRay optHit = BlockRay.from(player).filter(BlockRay.allFilter()).build();
        BlockState state = null;

        while(optHit.hasNext() && state == null){
            BlockRayHit ray =;
            Vector3d lookPos = ray.getBlockPosition().toDouble();
            BlockState blockState = player.getWorld().getBlock(lookPos.toInt());

            state = !blockState.getType().equals(BlockTypes.AIR)?blockState:null;



You can use the filter(Predicate)-Method to filter out block you don’t want. In your case you could make a list of blocks to ignore. For Example:

        Player player = event.getCause().first(Player.class).get();
        BlockRay optHit = BlockRay.from(player).filter(filterBlocks()).build();
        BlockRayHit hit =;
        BlockState state = hit.getExtent().getBlock(hit.getBlockPosition());

private static final ImmutableList<BlockType> blocks = ImmutableList.<BlockType>builder()
public static <E extends Extent> Predicate<BlockRayHit<E>> filterBlocks() {
        return input -> blocks.contains(input.getExtent().getBlockType(input.getBlockPosition()));
1 Like

How do you enable the display of the “minecraft:snow_layer” text? Sorry, irrelevant, but useful.

player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, TextStyles.BOLD, "minecraft:snow_layer"));
1 Like