Interface RayTrace<T extends Locatable>
- 
- Type Parameters:
- T- The type of- Locatablethat this ray trace will attempt to select
 
 public interface RayTrace<T extends Locatable>Builds a set of parameters to define a ray trace that traces from a source position to a target position (or in a specified direction), subject to the supplied constraints.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 the- ServerLocationthe ray is crossing in to is valid, regardless of what the ray has otherwise hit.
- select(Predicate)-- called when the- AABBof- Tis crossed by the ray trace, for- LocatableBlocks this is called directly after- continueWhileLocation(Predicate). This is the only predicate that can return a result, any .
- continueWhileBlock(Predicate)-- called if no selection was returned (if appropriate), checks the- LocatableBlockthe ray is entering. All predicates should return- trueif the ray should continue to trace through the block.
- continueWhileEntity(Predicate)-- called if no selection was returned (if appropriate), checks the- Entitythe ray has struck. All predicates should return- trueif the ray should continue to trace through the entity.
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static interfaceRayTrace.FactoryCreates relevant objects for ray tracing.
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static RayTrace<LocatableBlock>block()Creates aRayTracethat will attempt to select aLocatableBlock.RayTrace<T>continueUntil(Vector3d endPosition)Sets theVector3dposition where a ray trace should end.RayTrace<T>continueWhileBlock(java.util.function.Predicate<LocatableBlock> predicate)Provides aPredicatethat 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.RayTrace<T>continueWhileEntity(java.util.function.Predicate<Entity> predicate)Provides aPredicatethat 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.RayTrace<T>continueWhileLocation(java.util.function.Predicate<ServerLocation> predicate)Provides aPredicatethat allows a consumer to determine whether a givenServerLocationshould allow the trace to succeed.default RayTrace<T>direction(Living entity)RayTrace<T>direction(Vector3d direction)Sets the direction to trace in.static RayTrace<Entity>entity()java.util.Optional<RayTraceResult<T>>execute()Executes this ray trace and returns aRayTraceResultcontaining theLocatableif successful.RayTrace<T>limit(int distance)Sets how far this trace will look to find a match, passing all other constraints, before returning no results.static java.util.function.Predicate<LocatableBlock>nonAir()Returns aPredicatefor use inselect(Predicate)that selects non-air blocks.static java.util.function.Predicate<LocatableBlock>onlyAir()Returns aPredicatefor use incontinueWhileLocation(Predicate)that only allows a trace to continue if theLocatableBlockat the given position is air.RayTrace<T>reset()Resets this object to its original state.RayTrace<T>select(java.util.function.Predicate<T> filter)Determines the condition in which aLocatablehit will be considered successful.RayTrace<T>sourceEyePosition(Living entity)default RayTrace<T>sourcePosition(Entity entity)RayTrace<T>sourcePosition(Vector3d sourcePosition)Sets theVector3dposition to trace from.RayTrace<T>world(ServerWorld serverWorld)Sets theServerWorldto perform the ray trace in.
 
- 
- 
- 
Method Detail- 
blockstatic RayTrace<LocatableBlock> block() Creates aRayTracethat will attempt to select aLocatableBlock.- Returns:
- The ray trace builder.
 
 - 
onlyAirstatic java.util.function.Predicate<LocatableBlock> onlyAir() Returns aPredicatefor use incontinueWhileLocation(Predicate)that only allows a trace to continue if theLocatableBlockat the given position is air.- Returns:
- The predicate
 
 - 
nonAirstatic java.util.function.Predicate<LocatableBlock> nonAir() Returns aPredicatefor use inselect(Predicate)that selects non-air blocks.- Returns:
- The predicate
 
 - 
worldRayTrace<T> world(ServerWorld serverWorld) Sets theServerWorldto perform the ray trace in.- Parameters:
- serverWorld- The- ServerWorld
- Returns:
- This, for chaining
 
 - 
sourcePositiondefault RayTrace<T> sourcePosition(Entity entity) Sets thepositionto 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- The- Entity
- Returns:
- This, for chaining
 
 - 
sourceEyePositionRayTrace<T> sourceEyePosition(Living entity) Sets thepositionto trace from, based on the suppliedEntity'seye position.If Keys.EYE_POSITIONdoes not exist, this will throw anIllegalArgumentExceptioninstead.- Parameters:
- entity- The- Living
- Returns:
- This, for chaining
 
 - 
sourcePositionRayTrace<T> sourcePosition(Vector3d sourcePosition) Sets theVector3dposition to trace from.- Parameters:
- sourcePosition- The- Vector3d
- Returns:
- This, for chaining
 
 - 
directionRayTrace<T> direction(Vector3d direction) Sets the direction to trace in.If continueUntil(Vector3d)is set, this will be unset.- Parameters:
- direction- The- Vector3d
- Returns:
- This, for chaining
 
 - 
directiondefault RayTrace<T> direction(Living entity) Sets the direction to trace in, based on the direction thedirectionthe suppliedLivingis currently looking.If continueUntil(Vector3d)is set, this will be unset.- Parameters:
- entity- The- Living
- Returns:
- This, for chaining
 
 - 
limitRayTrace<T> limit(int distance) 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
 
 - 
continueUntilRayTrace<T> continueUntil(Vector3d endPosition) Sets theVector3dposition 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
 
 - 
continueWhileLocationRayTrace<T> continueWhileLocation(java.util.function.Predicate<ServerLocation> predicate) Provides aPredicatethat allows a consumer to determine whether a givenServerLocationshould allow the trace to succeed. The predicate should returntrueif the trace should proceed.This predicate will be checked when the boundary between two LocatableBlocks is crossed.- Parameters:
- predicate- The predicate to check
- Returns:
- This, for chaining
 
 - 
continueWhileBlockRayTrace<T> continueWhileBlock(java.util.function.Predicate<LocatableBlock> predicate) Provides aPredicatethat 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 LocatableBlocks, 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
 
 - 
continueWhileEntityRayTrace<T> continueWhileEntity(java.util.function.Predicate<Entity> predicate) Provides aPredicatethat 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 Entitybased ray trace, no entity ray trace calculations will be performed.- Parameters:
- predicate- The predicate
- Returns:
- This, for chaining
 
 - 
selectRayTrace<T> select(java.util.function.Predicate<T> filter) Determines the condition in which aLocatablehit will be considered successful.For example, if this ray trace is LocatableBlockspecific 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 a- RayTraceResult
- Returns:
- This, for chaining.
 
 - 
executejava.util.Optional<RayTraceResult<T>> execute() Executes this ray trace and returns aRayTraceResultcontaining theLocatableif successful.- Returns:
- The RayTraceResult, if any.
 
 
- 
 
-