-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java
This file contains 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,206 @@ | ||
package io.papermc.paper.raytracing; | ||
|
||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Entity; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Holds information about how to cast a raytrace. | ||
*/ | ||
public interface RayTraceConfiguration { | ||
|
||
/** | ||
* Creates a new builder. | ||
* | ||
* @return the new builder | ||
*/ | ||
@NotNull | ||
static Builder builder() { | ||
return new RayTraceConfigurationBuilderImpl(); | ||
} | ||
|
||
/** | ||
* Gets the maximum distance. | ||
* | ||
* @return the maximum distance | ||
*/ | ||
double maxDistance(); | ||
|
||
/** | ||
* Gets the FluidCollisionMode when looking for block collisions. | ||
* | ||
* @return the FluidCollisionMode | ||
*/ | ||
@Nullable | ||
FluidCollisionMode fluidCollisionMode(); | ||
|
||
/** | ||
* Gets if the raytrace will ignore passable blocks when looking for block collisions. | ||
* | ||
* @return if the raytrace will ignore passable blocks | ||
*/ | ||
boolean ignorePassableBlocks(); | ||
|
||
/** | ||
* Gets the size of the raytrace when looking for entity collisions. | ||
* | ||
* @return the raytrace size | ||
*/ | ||
double raySize(); | ||
|
||
/** | ||
* Gets the current entity filter. | ||
* | ||
* @return predicate for entities the ray can potentially collide with, or null to consider all entities | ||
*/ | ||
@Nullable | ||
Predicate<? super Entity> entityFilter(); | ||
|
||
/** | ||
* Gets the current block filter. | ||
* | ||
* @return predicate for blocks the ray can potentially collide with, or null to consider all blocks | ||
*/ | ||
@Nullable | ||
Predicate<? super Block> blockFilter(); | ||
|
||
/** | ||
* Gets which RayTraceTargets this configuration was made for. | ||
* | ||
* @return the targets | ||
*/ | ||
@NotNull | ||
List<Targets> targets(); | ||
|
||
/** | ||
* Helps you create a RayTraceConfiguration. | ||
*/ | ||
interface Builder { | ||
|
||
/** | ||
* Gets the maximum distance. | ||
* | ||
* @return the maximum distance | ||
*/ | ||
double maxDistance(); | ||
|
||
/** | ||
* Sets the maximum distance. | ||
* | ||
* @param maxDistance the new maxDistance | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder maxDistance(double maxDistance); | ||
|
||
/** | ||
* Gets the FluidCollisionMode when looking for block collisions. | ||
* | ||
* @return the FluidCollisionMode | ||
*/ | ||
@Nullable | ||
FluidCollisionMode fluidCollisionMode(); | ||
|
||
/** | ||
* Sets the FluidCollisionMode when looking for block collisions. | ||
* | ||
* @param fluidCollisionMode the new FluidCollisionMode | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder fluidCollisionMode(@Nullable FluidCollisionMode fluidCollisionMode); | ||
|
||
/** | ||
* Gets if the raytrace will ignore passable blocks when looking for block collisions. | ||
* | ||
* @return if the raytrace will ignore passable blocks | ||
*/ | ||
boolean ignorePassableBlocks(); | ||
|
||
/** | ||
* Gets if the raytrace will ignore passable blocks when looking for block collisions. | ||
* | ||
* @param ignorePassableBlocks if the raytrace should ignore passable blocks | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder ignorePassableBlocks(boolean ignorePassableBlocks); | ||
|
||
/** | ||
* Gets the size of the raytrace when looking for entity collisions. | ||
* | ||
* @return the raytrace size | ||
*/ | ||
double raySize(); | ||
|
||
/** | ||
* Sets the size of the raytrace when looking for entity collisions. | ||
* | ||
* @param raySize the new raytrace size | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder raySize(double raySize); | ||
|
||
/** | ||
* Gets the current entity filter when looking for entity collisions. | ||
* | ||
* @return predicate for entities the ray can potentially collide with, or null to consider all entities | ||
*/ | ||
@Nullable | ||
Predicate<? super Entity> entityFilter(); | ||
|
||
/** | ||
* Sets the current entity filter when looking for entity collisions. | ||
* | ||
* @param entityFilter predicate for entities the ray can potentially collide with, or null to consider all entities | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder entityFilter(@Nullable Predicate<? super Entity> entityFilter); | ||
|
||
/** | ||
* Gets the current block filter when looking for block collisions. | ||
* | ||
* @return predicate for blocks the ray can potentially collide with, or null to consider all blocks | ||
*/ | ||
@Nullable | ||
Predicate<? super Block> blockFilter(); | ||
|
||
/** | ||
* Sets the current block filter when looking for block collisions. | ||
* | ||
* @param blockFilter predicate for blocks the ray can potentially collide with, or null to consider all blocks | ||
* @return a reference to this object | ||
*/ | ||
@NotNull | ||
@Contract("_ -> this") | ||
Builder blockFilter(@Nullable Predicate<? super Block> blockFilter); | ||
|
||
/** | ||
* Builds a configuration based on the provided targets. | ||
* | ||
* @return the configuration | ||
*/ | ||
@NotNull | ||
RayTraceConfiguration target(@NotNull Targets first, @NotNull Targets... others); | ||
} | ||
|
||
/** | ||
* List of Targets the builder can target. | ||
*/ | ||
enum Targets { | ||
ENTITIES, | ||
BLOCKS | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java
This file contains 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,93 @@ | ||
package io.papermc.paper.raytracing; | ||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Entity; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class RayTraceConfigurationBuilderImpl implements RayTraceConfiguration.Builder { | ||
|
||
private double maxDistance; | ||
private FluidCollisionMode fluidCollisionMode = FluidCollisionMode.NEVER; | ||
private boolean ignorePassableBlocks; | ||
private double raySize = 0.0D; | ||
private Predicate<? super Entity> entityFilter; | ||
private Predicate<? super Block> blockFilter; | ||
|
||
|
||
@Override | ||
public double maxDistance() { | ||
return maxDistance; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder maxDistance(double maxDistance) { | ||
this.maxDistance = maxDistance; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @Nullable FluidCollisionMode fluidCollisionMode() { | ||
return fluidCollisionMode; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder fluidCollisionMode(@Nullable FluidCollisionMode fluidCollisionMode) { | ||
this.fluidCollisionMode = fluidCollisionMode; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean ignorePassableBlocks() { | ||
return ignorePassableBlocks; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder ignorePassableBlocks(boolean ignorePassableBlocks) { | ||
this.ignorePassableBlocks = ignorePassableBlocks; | ||
return this; | ||
} | ||
|
||
@Override | ||
public double raySize() { | ||
return raySize; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder raySize(double raySize) { | ||
this.raySize = raySize; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @Nullable Predicate<? super Entity> entityFilter() { | ||
return entityFilter; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder entityFilter(@Nullable Predicate<? super Entity> entityFilter) { | ||
this.entityFilter = entityFilter; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @Nullable Predicate<? super Block> blockFilter() { | ||
return blockFilter; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration.Builder blockFilter(@Nullable Predicate<? super Block> blockFilter) { | ||
this.blockFilter = blockFilter; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull RayTraceConfiguration target(@NotNull RayTraceConfiguration.Targets first, @NotNull RayTraceConfiguration.Targets... others) { | ||
List<RayTraceConfiguration.Targets> targets = new ArrayList<>(List.of(others)); // Need to make this immutable later | ||
targets.add(first); | ||
return new RayTraceConfigurationImpl(maxDistance, fluidCollisionMode, ignorePassableBlocks, raySize, entityFilter, blockFilter, targets); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java
This file contains 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,15 @@ | ||
package io.papermc.paper.raytracing; | ||
|
||
import org.bukkit.FluidCollisionMode; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Entity; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public record RayTraceConfigurationImpl(double maxDistance, @Nullable FluidCollisionMode fluidCollisionMode, | ||
boolean ignorePassableBlocks, double raySize, | ||
@Nullable Predicate<? super Entity> entityFilter, @Nullable Predicate<? super Block> blockFilter, | ||
@NotNull List<Targets> targets) implements RayTraceConfiguration { | ||
} |
This file contains 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
This file contains 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