Skip to content

Commit

Permalink
some adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Jan 4, 2025
1 parent f8a2709 commit 576ae99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -157,12 +158,19 @@ public interface PositionedRayTraceConfigurationBuilder {
PositionedRayTraceConfigurationBuilder blockFilter(@Nullable Predicate<? super Block> blockFilter);

/**
* Builds a configuration based on the provided targets.
* Gets the current set targets.
*
* @return the configuration
* @return the targets
*/
@Nullable
List<Targets> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) {


@Override
public @Nullable Location start() {
public @NotNull Location start() {
return this.start;
}

Expand All @@ -40,7 +40,7 @@ public PositionedRayTraceConfigurationBuilderImpl(World world) {
}

@Override
public @Nullable Vector direction() {
public @NotNull Vector direction() {
return this.direction;
}

Expand Down Expand Up @@ -117,18 +117,24 @@ public double raySize() {
}

@Override
public void target(final @NotNull Targets first, final @NotNull Targets... others) {
public @Nullable List<Targets> targets() {
return this.targets;
}

@Override
public @NotNull PositionedRayTraceConfigurationBuilder targets(final @NotNull Targets first, final @NotNull Targets... others) {
java.util.List<PositionedRayTraceConfigurationBuilder.Targets> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1247,8 +1249,8 @@ public RayTraceResult rayTrace(io.papermc.paper.math.Position start, Vector dire
}

@Override
public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Consumer<io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder> builderConsumer) {
io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl builder = new io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilderImpl(this);
public @org.jetbrains.annotations.Nullable RayTraceResult rayTrace(Consumer<PositionedRayTraceConfigurationBuilder> builderConsumer) {
PositionedRayTraceConfigurationBuilderImpl builder = new PositionedRayTraceConfigurationBuilderImpl(this);

builderConsumer.accept(builder);

Expand Down

0 comments on commit 576ae99

Please sign in to comment.