Interface RayTrace<T extends Locatable>
- Type Parameters:
T
- The type ofLocatable
that this ray trace will attempt to select
A ray trace will check supplied predicates in the following order in the case where multiple predicates should be checked:
continueWhileLocation(Predicate)
-- called when the boundary between two blocks is crossed, checking if theServerLocation
the ray is crossing in to is valid, regardless of what the ray has otherwise hit.select(Predicate)
-- called when theAABB
ofT
is crossed by the ray trace, forLocatableBlock
s this is called directly aftercontinueWhileLocation(Predicate)
. This is the only predicate that can return a result, any .continueWhileBlock(Predicate)
-- called if no selection was returned (if appropriate), checks theLocatableBlock
the ray is entering. All predicates should returntrue
if the ray should continue to trace through the block.continueWhileEntity(Predicate)
-- called if no selection was returned (if appropriate), checks theEntity
the ray has struck. All predicates should returntrue
if the ray should continue to trace through the entity.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Creates relevant objects for ray tracing. -
Method Summary
Modifier and TypeMethodDescriptionstatic RayTrace
<LocatableBlock> block()
Creates aRayTrace
that will attempt to select aLocatableBlock
.continueUntil
(Vector3d endPosition) Sets theVector3d
position where a ray trace should end.continueWhileBlock
(Predicate<LocatableBlock> predicate) Provides aPredicate
that allows a consumer to determine whether a givenLocatableBlock
(which has not been selected by the predicate provided inselect(Predicate)
should allow the trace to proceed.continueWhileEntity
(Predicate<Entity> predicate) Provides aPredicate
that allows a consumer to determine whether a givenEntity
(which has not been selected by the predicate provided inselect(Predicate)
should allow the trace to proceed.continueWhileLocation
(Predicate<ServerLocation> predicate) Provides aPredicate
that allows a consumer to determine whether a givenServerLocation
should allow the trace to succeed.Sets the direction to trace in.entity()
execute()
Executes this ray trace and returns aRayTraceResult
containing theLocatable
if successful.limit
(int distance) Sets how far this trace will look to find a match, passing all other constraints, before returning no results.static Predicate
<LocatableBlock> nonAir()
Returns aPredicate
for use inselect(Predicate)
that selects non-air blocks.static Predicate
<LocatableBlock> onlyAir()
Returns aPredicate
for use incontinueWhileLocation(Predicate)
that only allows a trace to continue if theLocatableBlock
at the given position is air.reset()
Resets this object to its original state.Determines the condition in which aLocatable
hit will be considered successful.sourceEyePosition
(Living entity) sourcePosition
(Entity entity) sourcePosition
(Vector3d sourcePosition) Sets theVector3d
position to trace from.world
(ServerWorld serverWorld) Sets theServerWorld
to perform the ray trace in.
-
Method Details
-
block
Creates aRayTrace
that will attempt to select aLocatableBlock
.- Returns:
- The ray trace builder.
-
entity
- Returns:
- The ray trace builder.
-
onlyAir
Returns aPredicate
for use incontinueWhileLocation(Predicate)
that only allows a trace to continue if theLocatableBlock
at the given position is air.- Returns:
- The predicate
-
nonAir
Returns aPredicate
for use inselect(Predicate)
that selects non-air blocks.- Returns:
- The predicate
-
world
Sets theServerWorld
to perform the ray trace in.- Parameters:
serverWorld
- TheServerWorld
- Returns:
- This, for chaining
-
sourcePosition
Sets theposition
to trace from, based on the suppliedEntity
'sposition
.This will use
Entity.position()
to determine the entity position. This may be unexpected if you wish to ray trace along the line of sight of the entity. In this scenario, usesourceEyePosition(Living)
instead.- Parameters:
entity
- TheEntity
- Returns:
- This, for chaining
-
sourceEyePosition
Sets theposition
to trace from, based on the suppliedEntity
'seye position
.If
Keys.EYE_POSITION
does not exist, this will throw anIllegalArgumentException
instead.- Parameters:
entity
- TheLiving
- Returns:
- This, for chaining
-
sourcePosition
Sets theVector3d
position to trace from.- Parameters:
sourcePosition
- TheVector3d
- Returns:
- This, for chaining
-
direction
Sets the direction to trace in.If
continueUntil(Vector3d)
is set, this will be unset.- Parameters:
direction
- TheVector3d
- Returns:
- This, for chaining
-
direction
Sets the direction to trace in, based on the direction thedirection
the suppliedLiving
is currently looking.If
continueUntil(Vector3d)
is set, this will be unset.- Parameters:
entity
- TheLiving
- Returns:
- This, for chaining
-
limit
Sets how far this trace will look to find a match, passing all other constraints, before returning no results.This defaults to a distance of 30. This will be ignored if a specific position is set via
continueUntil(Vector3d)
.- Parameters:
distance
- The distance- Returns:
- This, for chaining
-
continueUntil
Sets theVector3d
position where a ray trace should end.If
direction(Living)
ordirection(Vector3d)
is set, this will be unset and any limit set vialimit(int)
will be ignored.- Parameters:
endPosition
- The position- Returns:
- This, for chaining
-
continueWhileLocation
Provides aPredicate
that allows a consumer to determine whether a givenServerLocation
should allow the trace to succeed. The predicate should returntrue
if the trace should proceed.This predicate will be checked when the boundary between two
LocatableBlock
s is crossed.- Parameters:
predicate
- The predicate to check- Returns:
- This, for chaining
-
continueWhileBlock
Provides aPredicate
that allows a consumer to determine whether a givenLocatableBlock
(which has not been selected by the predicate provided inselect(Predicate)
should allow the trace to proceed.For example, if a trace is for
LocatableBlock
s, you may only want to continue the trace if it travels through air (generally used for line of sight purposes). In this case, the predicate may look like this:block -> { final BlockType type = block.blockState().type(); return type == BlockTypes.AIR.get() || type == BlockTypes.CAVE_AIR.get() || type == BlockTypes.VOID_AIR.get(); }
If this is not supplied, this defaults to always returning
true
.- Parameters:
predicate
- The predicate to check- Returns:
- This, for chaining
-
continueWhileEntity
Provides aPredicate
that allows a consumer to determine whether a givenEntity
(which has not been selected by the predicate provided inselect(Predicate)
should allow the trace to proceed.If this is not supplied, this will default to true, and if this is not an
Entity
based ray trace, no entity ray trace calculations will be performed.- Parameters:
predicate
- The predicate- Returns:
- This, for chaining
-
select
Determines the condition in which aLocatable
hit will be considered successful.For example, if this ray trace is
LocatableBlock
specific and you want to obtain the first non-air block, the predicate might look something like this:block -> { final BlockType type = block.blockState().type(); return !(type == BlockTypes.AIR.get() && type == BlockTypes.CAVE_AIR.get() && type == BlockTypes.VOID_AIR.get()); }
Given the other supplied conditions, if this supplied predicate returns
true
, the first hit will be returned as aLocatable
.If multiple predicates are provided, they will be combined using
Predicate.or(Predicate)
.A selection will happen before any predicate supplied to
continueWhileBlock(Predicate)
, but after anycontinueWhileLocation(Predicate)
is processed.- Parameters:
filter
- The filter to use to determine whether to return aRayTraceResult
- Returns:
- This, for chaining.
-
execute
Optional<RayTraceResult<T>> execute()Executes this ray trace and returns aRayTraceResult
containing theLocatable
if successful.- Returns:
- The
RayTraceResult
, if any.
-
reset
Resets this object to its original state.- Returns:
- This, for chaining.
-