-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add RayTraceConfigurationBuilder #11907
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d6a56da
Add RayTraceConfiguration
notTamion 0a98c80
work
notTamion f393d32
some adjustments
notTamion baf6058
jspecify and move Targets
notTamion 39b1267
singular
notTamion a557574
move some stuff
notTamion 17fa876
mutability
notTamion 191ee04
implement requests
notTamion 29e4bb8
Nullable annotation on vars
notTamion 1242322
a
notTamion c522be7
fixes
Machine-Maker 953e224
nullable preconditions
Machine-Maker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.papermc.paper.raytracing; | ||
|
||
import java.util.function.Predicate; | ||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.util.Vector; | ||
import org.checkerframework.checker.index.qual.NonNegative; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jspecify.annotations.NullMarked; | ||
|
||
/** | ||
* A builder for configuring a raytrace with a starting location | ||
* and direction. | ||
*/ | ||
@NullMarked | ||
public interface PositionedRayTraceConfigurationBuilder { | ||
|
||
/** | ||
* Sets the starting location. | ||
* | ||
* @param start the new starting location | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder start(Location start); | ||
|
||
/** | ||
* Sets the direction. | ||
* | ||
* @param direction the new direction | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder direction(Vector direction); | ||
|
||
/** | ||
* Sets the maximum distance. | ||
* | ||
* @param maxDistance the new maxDistance | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder maxDistance(@NonNegative double maxDistance); | ||
|
||
/** | ||
* Sets the FluidCollisionMode when looking for block collisions. | ||
* <p> | ||
* If collisions with passable blocks are ignored, fluid collisions are | ||
* ignored as well regardless of the fluid collision mode. | ||
* | ||
* @param fluidCollisionMode the new FluidCollisionMode | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder fluidCollisionMode(FluidCollisionMode fluidCollisionMode); | ||
|
||
/** | ||
* Sets whether the raytrace should ignore passable blocks when looking for | ||
* block collisions. | ||
* <p> | ||
* If collisions with passable blocks are ignored, fluid collisions are | ||
* ignored as well regardless of the fluid collision mode. | ||
* <p> | ||
* Portal blocks are only considered passable if the ray starts within them. | ||
* Apart from that collisions with portal blocks will be considered even if | ||
* collisions with passable blocks are otherwise ignored. | ||
* | ||
* @param ignorePassableBlocks if the raytrace should ignore passable blocks | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder ignorePassableBlocks(boolean ignorePassableBlocks); | ||
|
||
/** | ||
* Sets the size of the raytrace when looking for entity collisions. | ||
* | ||
* @param raySize the new raytrace size | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder raySize(@NonNegative double raySize); | ||
|
||
/** | ||
* Sets the current entity filter when looking for entity collisions. | ||
* | ||
* @param entityFilter predicate for entities the ray can potentially collide with | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder entityFilter(Predicate<? super Entity> entityFilter); | ||
|
||
/** | ||
* Sets the current block filter when looking for block collisions. | ||
* | ||
* @param blockFilter predicate for blocks the ray can potentially collide with | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder blockFilter(Predicate<? super Block> blockFilter); | ||
|
||
/** | ||
* Sets the targets for the rayTrace. | ||
* | ||
* @param first the first target | ||
* @param others the other targets | ||
* @return a reference to this object | ||
*/ | ||
@Contract(value = "_, _ -> this", mutates = "this") | ||
PositionedRayTraceConfigurationBuilder targets(RayTraceTarget first, RayTraceTarget... others); | ||
} |
9 changes: 9 additions & 0 deletions
9
paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTarget.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.papermc.paper.raytracing; | ||
|
||
/** | ||
* List of Targets a builder can target. | ||
*/ | ||
public enum RayTraceTarget { | ||
ENTITY, | ||
BLOCK | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.papermc.paper.raytracing; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.util.EnumSet; | ||
import java.util.OptionalDouble; | ||
import java.util.function.Predicate; | ||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.util.Vector; | ||
import org.jspecify.annotations.NullMarked; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
@NullMarked | ||
public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRayTraceConfigurationBuilder { | ||
notTamion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public @Nullable Location start; | ||
public @Nullable Vector direction; | ||
public OptionalDouble maxDistance = OptionalDouble.empty(); | ||
public FluidCollisionMode fluidCollisionMode = FluidCollisionMode.NEVER; | ||
public boolean ignorePassableBlocks; | ||
public double raySize = 0.0D; | ||
public @Nullable Predicate<? super Entity> entityFilter; | ||
public @Nullable Predicate<? super Block> blockFilter; | ||
public EnumSet<RayTraceTarget> targets = EnumSet.noneOf(RayTraceTarget.class); | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder start(final Location start) { | ||
Preconditions.checkArgument(start != null, "start must not be null"); | ||
this.start = start.clone(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder direction(final Vector direction) { | ||
Preconditions.checkArgument(direction != null, "direction must not be null"); | ||
this.direction = direction.clone(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder maxDistance(final double maxDistance) { | ||
Preconditions.checkArgument(maxDistance >= 0, "maxDistance must be non-negative"); | ||
this.maxDistance = OptionalDouble.of(maxDistance); | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder fluidCollisionMode(final FluidCollisionMode fluidCollisionMode) { | ||
Preconditions.checkArgument(fluidCollisionMode != null, "fluidCollisionMode must not be null"); | ||
this.fluidCollisionMode = fluidCollisionMode; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder ignorePassableBlocks(final boolean ignorePassableBlocks) { | ||
this.ignorePassableBlocks = ignorePassableBlocks; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder raySize(final double raySize) { | ||
Preconditions.checkArgument(raySize >= 0, "raySize must be non-negative"); | ||
this.raySize = raySize; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder entityFilter(final Predicate<? super Entity> entityFilter) { | ||
Preconditions.checkArgument(entityFilter != null, "entityFilter must not be null"); | ||
this.entityFilter = entityFilter; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder blockFilter(final Predicate<? super Block> blockFilter) { | ||
Preconditions.checkArgument(blockFilter != null, "blockFilter must not be null"); | ||
this.blockFilter = blockFilter; | ||
return this; | ||
} | ||
|
||
@Override | ||
public PositionedRayTraceConfigurationBuilder targets(final RayTraceTarget first, final RayTraceTarget... others) { | ||
Preconditions.checkArgument(first != null, "first must not be null"); | ||
Preconditions.checkArgument(others != null, "others must not be null"); | ||
this.targets = EnumSet.of(first, others); | ||
return this; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.