From efbab5d49eb7000cd4646a1785c6239fe10d0c62 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 4 Jan 2025 14:42:50 +0100 Subject: [PATCH 1/5] Add RayTraceConfiguration --- .../raytracing/RayTraceConfiguration.java | 206 ++++++++++++++++++ .../RayTraceConfigurationBuilderImpl.java | 93 ++++++++ .../raytracing/RayTraceConfigurationImpl.java | 15 ++ paper-api/src/main/java/org/bukkit/World.java | 25 +++ .../org/bukkit/craftbukkit/CraftWorld.java | 12 + 5 files changed, 351 insertions(+) create mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java create mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java create mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java new file mode 100644 index 000000000000..293ad30b3653 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java @@ -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 entityFilter(); + + /** + * Gets the current block filter. + * + * @return predicate for blocks the ray can potentially collide with, or null to consider all blocks + */ + @Nullable + Predicate blockFilter(); + + /** + * Gets which RayTraceTargets this configuration was made for. + * + * @return the targets + */ + @NotNull + List 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 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 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 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 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 + } +} diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java new file mode 100644 index 000000000000..b6a9e03023ce --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java @@ -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 entityFilter; + private Predicate 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 entityFilter() { + return entityFilter; + } + + @Override + public @NotNull RayTraceConfiguration.Builder entityFilter(@Nullable Predicate entityFilter) { + this.entityFilter = entityFilter; + return this; + } + + @Override + public @Nullable Predicate blockFilter() { + return blockFilter; + } + + @Override + public @NotNull RayTraceConfiguration.Builder blockFilter(@Nullable Predicate blockFilter) { + this.blockFilter = blockFilter; + return this; + } + + @Override + public @NotNull RayTraceConfiguration target(@NotNull RayTraceConfiguration.Targets first, @NotNull RayTraceConfiguration.Targets... others) { + List 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); + } +} diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java new file mode 100644 index 000000000000..ffe49cd1ecc9 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java @@ -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 entityFilter, @Nullable Predicate blockFilter, + @NotNull List targets) implements RayTraceConfiguration { +} diff --git a/paper-api/src/main/java/org/bukkit/World.java b/paper-api/src/main/java/org/bukkit/World.java index e5e6cdec5fbb..afc011b43831 100644 --- a/paper-api/src/main/java/org/bukkit/World.java +++ b/paper-api/src/main/java/org/bukkit/World.java @@ -1938,6 +1938,31 @@ default Iterable audiences() { @Nullable RayTraceResult rayTrace(io.papermc.paper.math.@NotNull Position start, @NotNull Vector direction, double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode, boolean ignorePassableBlocks, double raySize, @Nullable Predicate filter, @Nullable Predicate canCollide); // Paper end + /** + * Performs a ray trace that checks for both block and entity collisions. + *

+ * Block collisions use the blocks' precise collision shapes. The + * raySize parameter is only taken into account for entity + * collision checks. + *

+ * If collisions with passable blocks are ignored, fluid collisions are + * ignored as well regardless of the fluid collision mode. + *

+ * 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. + *

+ * This may cause loading of chunks! Some implementations may impose + * artificial restrictions on the maximum distance. + * + * @param start the start position + * @param direction the ray direction + * @param config the configuration + * @return the closest ray trace hit result with either a block or an + * entity, or null if there is no hit + */ + @Nullable RayTraceResult rayTrace(@NotNull Location start, @NotNull Vector direction, @NotNull io.papermc.paper.raytracing.RayTraceConfiguration config); + /** * Gets the default spawn {@link Location} of this world * diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 544305f9d08e..da52ce132189 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableMap; import com.mojang.datafixers.util.Pair; import io.papermc.paper.FeatureHooks; +import io.papermc.paper.raytracing.RayTraceConfiguration; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.io.File; @@ -1246,6 +1247,17 @@ public RayTraceResult rayTrace(io.papermc.paper.math.Position start, Vector dire return blockHit; } + @Override + public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Location start, Vector direction, io.papermc.paper.raytracing.RayTraceConfiguration config) { + List targets = config.targets(); + if (targets.contains(io.papermc.paper.raytracing.RayTraceConfiguration.Targets.ENTITIES)) { + if(targets.contains(io.papermc.paper.raytracing.RayTraceConfiguration.Targets.BLOCKS)) + return this.rayTrace(start, direction, config.maxDistance(), config.fluidCollisionMode(), config.ignorePassableBlocks(), config.raySize(), config.entityFilter(), config.blockFilter()); + return this.rayTraceEntities(start, direction, config.maxDistance(), config.raySize(), config.entityFilter()); + } + return this.rayTraceBlocks(start, direction, config.maxDistance(), config.fluidCollisionMode(), config.ignorePassableBlocks(), config.blockFilter()); + } + @Override public List getPlayers() { List list = new ArrayList(this.world.players().size()); From 0cc2263128682d0130cd66b489c4d0df66bd8c83 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:14:08 +0100 Subject: [PATCH 2/5] work --- ...ositionedRayTraceConfigurationBuilder.java | 174 +++++++++++++++ .../raytracing/RayTraceConfiguration.java | 206 ------------------ .../RayTraceConfigurationBuilderImpl.java | 93 -------- .../raytracing/RayTraceConfigurationImpl.java | 15 -- paper-api/src/main/java/org/bukkit/World.java | 7 +- ...ionedRayTraceConfigurationBuilderImpl.java | 134 ++++++++++++ .../org/bukkit/craftbukkit/CraftWorld.java | 15 +- 7 files changed, 317 insertions(+), 327 deletions(-) create mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java delete mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java delete mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java delete mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java create mode 100644 paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java new file mode 100644 index 000000000000..6144350e3c45 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java @@ -0,0 +1,174 @@ +package io.papermc.paper.raytracing; + +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.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.function.Predicate; + +/** + * Holds information about how to cast a raytrace. + */ +public interface PositionedRayTraceConfigurationBuilder { + + /** + * Gets the starting location. + * + * @return the starting location + */ + @Nullable + Location start(); + + /** + * Sets the starting location. + * + * @param start the new starting location + * @return a reference to this object + */ + @NotNull + @Contract("_ -> this") + PositionedRayTraceConfigurationBuilder start(@NotNull Location start); + + /** + * Gets the direction. + * + * @return the direction + */ + @Nullable + Vector direction(); + + /** + * Sets the direction. + * + * @param direction the new direction + * @return a reference to this object + */ + @NotNull + @Contract("_ -> this") + PositionedRayTraceConfigurationBuilder direction(@NotNull Vector direction); + + /** + * 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") + PositionedRayTraceConfigurationBuilder maxDistance(double maxDistance); + + /** + * Gets the FluidCollisionMode when looking for block collisions. + * + * @return the FluidCollisionMode + */ + @NotNull + FluidCollisionMode fluidCollisionMode(); + + /** + * Sets the FluidCollisionMode when looking for block collisions. + * + * @param fluidCollisionMode the new FluidCollisionMode + * @return a reference to this object + */ + @NotNull + @Contract("_ -> this") + PositionedRayTraceConfigurationBuilder fluidCollisionMode(@NotNull 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") + PositionedRayTraceConfigurationBuilder 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") + PositionedRayTraceConfigurationBuilder 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 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") + PositionedRayTraceConfigurationBuilder entityFilter(@Nullable Predicate 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 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") + PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate blockFilter); + + /** + * Builds a configuration based on the provided targets. + * + * @return the configuration + */ + @NotNull + void target(@NotNull Targets first, @NotNull Targets... others); + + /** + * List of Targets the builder can target. + */ + enum Targets { + ENTITIES, + BLOCKS + } +} diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java deleted file mode 100644 index 293ad30b3653..000000000000 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfiguration.java +++ /dev/null @@ -1,206 +0,0 @@ -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 entityFilter(); - - /** - * Gets the current block filter. - * - * @return predicate for blocks the ray can potentially collide with, or null to consider all blocks - */ - @Nullable - Predicate blockFilter(); - - /** - * Gets which RayTraceTargets this configuration was made for. - * - * @return the targets - */ - @NotNull - List 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 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 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 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 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 - } -} diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java deleted file mode 100644 index b6a9e03023ce..000000000000 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationBuilderImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -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 entityFilter; - private Predicate 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 entityFilter() { - return entityFilter; - } - - @Override - public @NotNull RayTraceConfiguration.Builder entityFilter(@Nullable Predicate entityFilter) { - this.entityFilter = entityFilter; - return this; - } - - @Override - public @Nullable Predicate blockFilter() { - return blockFilter; - } - - @Override - public @NotNull RayTraceConfiguration.Builder blockFilter(@Nullable Predicate blockFilter) { - this.blockFilter = blockFilter; - return this; - } - - @Override - public @NotNull RayTraceConfiguration target(@NotNull RayTraceConfiguration.Targets first, @NotNull RayTraceConfiguration.Targets... others) { - List 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); - } -} diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java deleted file mode 100644 index ffe49cd1ecc9..000000000000 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceConfigurationImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -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 entityFilter, @Nullable Predicate blockFilter, - @NotNull List targets) implements RayTraceConfiguration { -} diff --git a/paper-api/src/main/java/org/bukkit/World.java b/paper-api/src/main/java/org/bukkit/World.java index afc011b43831..f1d561acd0ad 100644 --- a/paper-api/src/main/java/org/bukkit/World.java +++ b/paper-api/src/main/java/org/bukkit/World.java @@ -1,6 +1,7 @@ package org.bukkit; import java.io.File; +import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder; import org.bukkit.generator.ChunkGenerator; import java.util.ArrayList; @@ -1955,13 +1956,11 @@ default Iterable audiences() { * This may cause loading of chunks! Some implementations may impose * artificial restrictions on the maximum distance. * - * @param start the start position - * @param direction the ray direction - * @param config the configuration + * @param builderConsumer consumer for the builder * @return the closest ray trace hit result with either a block or an * entity, or null if there is no hit */ - @Nullable RayTraceResult rayTrace(@NotNull Location start, @NotNull Vector direction, @NotNull io.papermc.paper.raytracing.RayTraceConfiguration config); + @Nullable RayTraceResult rayTrace(@NotNull Consumer builderConsumer); /** * Gets the default spawn {@link Location} of this world diff --git a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java new file mode 100644 index 000000000000..e71ab887ac06 --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java @@ -0,0 +1,134 @@ +package io.papermc.paper.raytracing; + +import org.bukkit.FluidCollisionMode; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.util.RayTraceResult; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.List; +import java.util.function.Predicate; + +public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRayTraceConfigurationBuilder { + + private World world; + private Location start; + private Vector direction; + private double maxDistance; + private org.bukkit.FluidCollisionMode fluidCollisionMode = org.bukkit.FluidCollisionMode.NEVER; + private boolean ignorePassableBlocks; + private double raySize = 0.0D; + private java.util.function.Predicate entityFilter; + private java.util.function.Predicate blockFilter; + private List targets; + + public PositionedRayTraceConfigurationBuilderImpl(World world) { + this.world = world; + } + + + @Override + public @Nullable Location start() { + return this.start; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder start(final @NotNull Location start) { + this.start = start; + return this; + } + + @Override + public @Nullable Vector direction() { + return this.direction; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder direction(final @NotNull Vector direction) { + this.direction = direction; + return this; + } + + @Override + public double maxDistance() { + return maxDistance; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder maxDistance(double maxDistance) { + this.maxDistance = maxDistance; + return this; + } + + @Override + public @NotNull FluidCollisionMode fluidCollisionMode() { + return fluidCollisionMode; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder fluidCollisionMode(@NotNull FluidCollisionMode fluidCollisionMode) { + this.fluidCollisionMode = fluidCollisionMode; + return this; + } + + @Override + public boolean ignorePassableBlocks() { + return ignorePassableBlocks; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder ignorePassableBlocks(boolean ignorePassableBlocks) { + this.ignorePassableBlocks = ignorePassableBlocks; + return this; + } + + @Override + public double raySize() { + return raySize; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder raySize(double raySize) { + this.raySize = raySize; + return this; + } + + @Override + public @Nullable Predicate entityFilter() { + return entityFilter; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder entityFilter(@Nullable Predicate entityFilter) { + this.entityFilter = entityFilter; + return this; + } + + @Override + public @Nullable Predicate blockFilter() { + return blockFilter; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate blockFilter) { + this.blockFilter = blockFilter; + return this; + } + + @Override + public void target(final @NotNull Targets first, final @NotNull Targets... others) { + java.util.List targets = new java.util.ArrayList<>(java.util.List.of(others)); + targets.add(first); + this.targets = targets; + } + + public RayTraceResult cast() { + if (targets.contains(Targets.ENTITIES)) { + if(targets.contains(Targets.BLOCKS)) + return world.rayTrace(this.start, this.direction, this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); + return world.rayTraceEntities(this.start, this.direction, this.maxDistance(), this.raySize(), this.entityFilter()); + } + return world.rayTraceBlocks(this.start, this.direction, this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.blockFilter()); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index da52ce132189..56b04a469a6b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -6,7 +6,6 @@ import com.google.common.collect.ImmutableMap; import com.mojang.datafixers.util.Pair; import io.papermc.paper.FeatureHooks; -import io.papermc.paper.raytracing.RayTraceConfiguration; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.io.File; @@ -1248,14 +1247,12 @@ public RayTraceResult rayTrace(io.papermc.paper.math.Position start, Vector dire } @Override - public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Location start, Vector direction, io.papermc.paper.raytracing.RayTraceConfiguration config) { - List targets = config.targets(); - if (targets.contains(io.papermc.paper.raytracing.RayTraceConfiguration.Targets.ENTITIES)) { - if(targets.contains(io.papermc.paper.raytracing.RayTraceConfiguration.Targets.BLOCKS)) - return this.rayTrace(start, direction, config.maxDistance(), config.fluidCollisionMode(), config.ignorePassableBlocks(), config.raySize(), config.entityFilter(), config.blockFilter()); - return this.rayTraceEntities(start, direction, config.maxDistance(), config.raySize(), config.entityFilter()); - } - return this.rayTraceBlocks(start, direction, config.maxDistance(), config.fluidCollisionMode(), config.ignorePassableBlocks(), config.blockFilter()); + public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Consumer builderConsumer) { + io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl builder = new io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl(this); + + builderConsumer.accept(builder); + + return builder.cast(); } @Override From 1e7f44832b80c2e1887541d4adbcb3823cf58d1a Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sat, 4 Jan 2025 22:27:33 +0100 Subject: [PATCH 3/5] some adjustments --- ...PositionedRayTraceConfigurationBuilder.java | 16 +++++++++++++--- ...tionedRayTraceConfigurationBuilderImpl.java | 18 ++++++++++++------ .../org/bukkit/craftbukkit/CraftWorld.java | 6 ++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java index 6144350e3c45..2e9efaa174a6 100644 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; import java.util.function.Predicate; /** @@ -157,12 +158,21 @@ public interface PositionedRayTraceConfigurationBuilder { PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate blockFilter); /** - * Builds a configuration based on the provided targets. + * Gets the current set targets. * - * @return the configuration + * @return the targets + */ + @Nullable + List targets(); + + /** + * Sets the targets for the rayTrace. + * + * @return a reference to this object */ @NotNull - void target(@NotNull Targets first, @NotNull Targets... others); + @Contract("_, _ -> this") + PositionedRayTraceConfigurationBuilder targets(@NotNull Targets first, @NotNull Targets... others); /** * List of Targets the builder can target. diff --git a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java index e71ab887ac06..5883aa13eb0f 100644 --- a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java @@ -29,7 +29,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) { @Override - public @Nullable Location start() { + public @NotNull Location start() { return this.start; } @@ -40,7 +40,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) { } @Override - public @Nullable Vector direction() { + public @NotNull Vector direction() { return this.direction; } @@ -117,18 +117,24 @@ public double raySize() { } @Override - public void target(final @NotNull Targets first, final @NotNull Targets... others) { + public @Nullable List targets() { + return this.targets; + } + + @Override + public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull Targets first, final @NotNull Targets... others) { java.util.List targets = new java.util.ArrayList<>(java.util.List.of(others)); targets.add(first); this.targets = targets; + return this; } public RayTraceResult cast() { if (targets.contains(Targets.ENTITIES)) { if(targets.contains(Targets.BLOCKS)) - return world.rayTrace(this.start, this.direction, this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); - return world.rayTraceEntities(this.start, this.direction, this.maxDistance(), this.raySize(), this.entityFilter()); + return world.rayTrace(this.start(), this.direction(), this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); + return world.rayTraceEntities(this.start(), this.direction(), this.maxDistance(), this.raySize(), this.entityFilter()); } - return world.rayTraceBlocks(this.start, this.direction, this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.blockFilter()); + return world.rayTraceBlocks(this.start(), this.direction(), this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.blockFilter()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 56b04a469a6b..f6d7890ebafd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -6,6 +6,8 @@ import com.google.common.collect.ImmutableMap; import com.mojang.datafixers.util.Pair; import io.papermc.paper.FeatureHooks; +import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder; +import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import java.io.File; @@ -1247,8 +1249,8 @@ public RayTraceResult rayTrace(io.papermc.paper.math.Position start, Vector dire } @Override - public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Consumer builderConsumer) { - io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl builder = new io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl(this); + public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Consumer builderConsumer) { + PositionedRayTraceConfigurationBuilderImpl builder = new PositionedRayTraceConfigurationBuilderImpl(this); builderConsumer.accept(builder); From 7f1fbe2e9699e490faae63c71bbb48807fe38f3c Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Sun, 5 Jan 2025 21:06:35 +0100 Subject: [PATCH 4/5] jspecify and move Targets --- ...ositionedRayTraceConfigurationBuilder.java | 33 +++++-------------- .../paper/raytracing/RayTraceTargets.java | 9 +++++ ...ionedRayTraceConfigurationBuilderImpl.java | 15 +++++---- 3 files changed, 25 insertions(+), 32 deletions(-) create mode 100644 paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java index 2e9efaa174a6..bcfe452cd44b 100644 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java @@ -6,14 +6,15 @@ import org.bukkit.entity.Entity; import org.bukkit.util.Vector; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import java.util.List; import java.util.function.Predicate; /** * Holds information about how to cast a raytrace. */ +@NullMarked public interface PositionedRayTraceConfigurationBuilder { /** @@ -30,9 +31,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param start the new starting location * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder start(@NotNull Location start); + PositionedRayTraceConfigurationBuilder start(Location start); /** * Gets the direction. @@ -48,9 +48,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param direction the new direction * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder direction(@NotNull Vector direction); + PositionedRayTraceConfigurationBuilder direction(Vector direction); /** * Gets the maximum distance. @@ -65,7 +64,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param maxDistance the new maxDistance * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder maxDistance(double maxDistance); @@ -74,7 +72,6 @@ public interface PositionedRayTraceConfigurationBuilder { * * @return the FluidCollisionMode */ - @NotNull FluidCollisionMode fluidCollisionMode(); /** @@ -83,9 +80,8 @@ public interface PositionedRayTraceConfigurationBuilder { * @param fluidCollisionMode the new FluidCollisionMode * @return a reference to this object */ - @NotNull @Contract("_ -> this") - PositionedRayTraceConfigurationBuilder fluidCollisionMode(@NotNull FluidCollisionMode fluidCollisionMode); + PositionedRayTraceConfigurationBuilder fluidCollisionMode(FluidCollisionMode fluidCollisionMode); /** * Gets if the raytrace will ignore passable blocks when looking for block collisions. @@ -100,7 +96,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param ignorePassableBlocks if the raytrace should ignore passable blocks * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder ignorePassableBlocks(boolean ignorePassableBlocks); @@ -117,7 +112,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @param raySize the new raytrace size * @return a reference to this object */ - @NotNull @Contract("_ -> this") PositionedRayTraceConfigurationBuilder raySize(double raySize); @@ -135,7 +129,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @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") PositionedRayTraceConfigurationBuilder entityFilter(@Nullable Predicate entityFilter); @@ -153,7 +146,6 @@ public interface PositionedRayTraceConfigurationBuilder { * @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") PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate blockFilter); @@ -163,22 +155,13 @@ public interface PositionedRayTraceConfigurationBuilder { * @return the targets */ @Nullable - List targets(); + List targets(); /** * Sets the targets for the rayTrace. * * @return a reference to this object */ - @NotNull @Contract("_, _ -> this") - PositionedRayTraceConfigurationBuilder targets(@NotNull Targets first, @NotNull Targets... others); - - /** - * List of Targets the builder can target. - */ - enum Targets { - ENTITIES, - BLOCKS - } + PositionedRayTraceConfigurationBuilder targets(RayTraceTargets first, RayTraceTargets... others); } diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java new file mode 100644 index 000000000000..77c5ba6758e4 --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java @@ -0,0 +1,9 @@ +package io.papermc.paper.raytracing; + +/** + * List of Targets a builder can target. + */ +public enum RayTraceTargets { + ENTITIES, + BLOCKS +} diff --git a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java index 5883aa13eb0f..1a8cbe080c02 100644 --- a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java @@ -7,6 +7,7 @@ import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; @@ -21,7 +22,7 @@ public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRay private double raySize = 0.0D; private java.util.function.Predicate entityFilter; private java.util.function.Predicate blockFilter; - private List targets; + private List targets; public PositionedRayTraceConfigurationBuilderImpl(World world) { this.world = world; @@ -34,7 +35,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) { } @Override - public @NotNull PositionedRayTraceConfigurationBuilder start(final @NotNull Location start) { + public PositionedRayTraceConfigurationBuilder start(final @NotNull Location start) { this.start = start; return this; } @@ -117,21 +118,21 @@ public double raySize() { } @Override - public @Nullable List targets() { + public @Nullable List targets() { return this.targets; } @Override - public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull Targets first, final @NotNull Targets... others) { - java.util.List targets = new java.util.ArrayList<>(java.util.List.of(others)); + public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull RayTraceTargets first, final @NotNull RayTraceTargets... others) { + List targets = new ArrayList<>(List.of(others)); targets.add(first); this.targets = targets; return this; } public RayTraceResult cast() { - if (targets.contains(Targets.ENTITIES)) { - if(targets.contains(Targets.BLOCKS)) + if (targets.contains(RayTraceTargets.ENTITIES)) { + if(targets.contains(RayTraceTargets.BLOCKS)) return world.rayTrace(this.start(), this.direction(), this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); return world.rayTraceEntities(this.start(), this.direction(), this.maxDistance(), this.raySize(), this.entityFilter()); } From 7fc168e4f4b75b65729e3db9d5aaf92690761724 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:46:32 +0100 Subject: [PATCH 5/5] singular --- .../PositionedRayTraceConfigurationBuilder.java | 4 ++-- .../{RayTraceTargets.java => RayTraceTarget.java} | 2 +- .../PositionedRayTraceConfigurationBuilderImpl.java | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) rename paper-api/src/main/java/io/papermc/paper/raytracing/{RayTraceTargets.java => RayTraceTarget.java} (79%) diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java index bcfe452cd44b..66de82b0b9b2 100644 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilder.java @@ -155,7 +155,7 @@ public interface PositionedRayTraceConfigurationBuilder { * @return the targets */ @Nullable - List targets(); + List targets(); /** * Sets the targets for the rayTrace. @@ -163,5 +163,5 @@ public interface PositionedRayTraceConfigurationBuilder { * @return a reference to this object */ @Contract("_, _ -> this") - PositionedRayTraceConfigurationBuilder targets(RayTraceTargets first, RayTraceTargets... others); + PositionedRayTraceConfigurationBuilder targets(RayTraceTarget first, RayTraceTarget... others); } diff --git a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTarget.java similarity index 79% rename from paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java rename to paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTarget.java index 77c5ba6758e4..bfb1df4e5983 100644 --- a/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTargets.java +++ b/paper-api/src/main/java/io/papermc/paper/raytracing/RayTraceTarget.java @@ -3,7 +3,7 @@ /** * List of Targets a builder can target. */ -public enum RayTraceTargets { +public enum RayTraceTarget { ENTITIES, BLOCKS } diff --git a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java index 1a8cbe080c02..d3b75cd7e7f8 100644 --- a/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/raytracing/PositionedRayTraceConfigurationBuilderImpl.java @@ -22,7 +22,7 @@ public class PositionedRayTraceConfigurationBuilderImpl implements PositionedRay private double raySize = 0.0D; private java.util.function.Predicate entityFilter; private java.util.function.Predicate blockFilter; - private List targets; + private List targets; public PositionedRayTraceConfigurationBuilderImpl(World world) { this.world = world; @@ -118,21 +118,21 @@ public double raySize() { } @Override - public @Nullable List targets() { + public @Nullable List targets() { return this.targets; } @Override - public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull RayTraceTargets first, final @NotNull RayTraceTargets... others) { - List targets = new ArrayList<>(List.of(others)); + public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull RayTraceTarget first, final @NotNull RayTraceTarget... others) { + List targets = new ArrayList<>(List.of(others)); targets.add(first); this.targets = targets; return this; } public RayTraceResult cast() { - if (targets.contains(RayTraceTargets.ENTITIES)) { - if(targets.contains(RayTraceTargets.BLOCKS)) + if (targets.contains(RayTraceTarget.ENTITIES)) { + if(targets.contains(RayTraceTarget.BLOCKS)) return world.rayTrace(this.start(), this.direction(), this.maxDistance(), this.fluidCollisionMode(), this.ignorePassableBlocks(), this.raySize(), this.entityFilter(), this.blockFilter()); return world.rayTraceEntities(this.start(), this.direction(), this.maxDistance(), this.raySize(), this.entityFilter()); }