From 576ae99ef1d52eeb17bad200dc8c2f1f7701e557 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] some adjustments --- ...PositionedRayTraceConfigurationBuilder.java | 14 +++++++++++--- ...tionedRayTraceConfigurationBuilderImpl.java | 18 ++++++++++++------ .../org/bukkit/craftbukkit/CraftWorld.java | 6 ++++-- 3 files changed, 27 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..441f1211f434 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,19 @@ 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. */ @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);