Skip to content

Add additional ray trace API #12162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

TonytheMacaroni
Copy link
Contributor

@TonytheMacaroni TonytheMacaroni commented Feb 23, 2025

Supersedes #11166.

  • Adds overloads to World#rayTrace and World#rayTraceBlocks, as well as the method PositionedRayTraceConfigurationBuilder#blockCollisionMode, that take a BlockCollisionMode instead of the boolean ignorePassableBlocks to determine block collisions.
  • Add FluidCollisionMode.WATER.
  • Remove outdated javadocs on World#rayTrace, World#rayTraceBlocks, PositionedRayTraceConfigurationBuilder#fluidCollisionMode, and PositionedRayTraceConfigurationBuilder#ignorePassableBlocks that mention caveats with portal blocks and fluids that no longer exist. Portal blocks are always considered 'passable', and the value of ignorePassableBlocks has no effect on fluid collisions.

@TonytheMacaroni TonytheMacaroni requested a review from a team as a code owner February 23, 2025 00:07
@Warriorrrr Warriorrrr added type: feature Request for a new Feature. scope: api labels Feb 25, 2025
@Warriorrrr Warriorrrr moved this from Awaiting review to Changes required in Paper PR Queue Mar 23, 2025
@TonytheMacaroni TonytheMacaroni force-pushed the additional-raytrace-api branch 2 times, most recently from 9244d76 to ce89a06 Compare March 24, 2025 15:03
Copy link
Member

@notTamion notTamion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! might be nice to mention something in the ignorePassable jdocs (at least on the builder) that its equivalent to setting the block collision mode to the respective value

@github-project-automation github-project-automation bot moved this from Changes required to Awaiting final testing in Paper PR Queue Mar 24, 2025
@lynxplay lynxplay force-pushed the additional-raytrace-api branch from 040c8b7 to d4fc780 Compare April 25, 2025 18:06
@lynxplay lynxplay force-pushed the additional-raytrace-api branch from d4fc780 to 8245d9d Compare May 2, 2025 19:50
@Owen1212055
Copy link
Member

The only thing I am not sure about is the whole fluid conditions.
It seems very arbitrary and at least I don't see why we should be adding our own conditions esp when its fairly easy to just check the blockstate directly.

@TonytheMacaroni
Copy link
Contributor Author

TonytheMacaroni commented May 18, 2025

Checking using the block filter doesn't really work. As an example:

Location location = ...;
World world = location.getWorld();

// Hits collidable blocks & lava fluid blocks
world.rayTrace(builder -> builder
    .blockCollisionMode(BlockCollisionMode.COLLIDER)
    .fluidCollisionMode(FluidCollisionMode.LAVA)
    .targets(RayTraceTarget.BLOCK)
);

// Hits non-waterlogged collidable blocks & lava fluid blocks
world.rayTrace(builder -> builder
    .blockCollisionMode(BlockCollisionMode.COLLIDER)
    .fluidCollisionMode(FluidCollisionMode.ALWAYS)
    .blockFilter(block -> {
        FluidData data = world.getFluidData(block.getX(), block.getY(), block.getZ());
        Fluid fluid = data.getFluidType();

        return fluid == Fluid.EMPTY || fluid == Fluid.LAVA || fluid == Fluid.FLOWING_LAVA;
    })
    .targets(RayTraceTarget.BLOCK)
);

The block filter can't really be used to be distinguish hitting the block part of a waterlogged block, or the fluid part.
An alternative to FluidCollisionMode.WATER/FluidCollisionMode.LAVA would be to add in a fluid filter that takes in the FluidData, which would only determine fluid collisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: api type: feature Request for a new Feature.
Projects
Status: Awaiting final testing
Development

Successfully merging this pull request may close these issues.

8 participants