From 2e4d53fcb0809a6eadab2b905a3598d754ef509d Mon Sep 17 00:00:00 2001 From: gamma-delta Date: Wed, 20 Nov 2024 09:34:59 -0600 Subject: [PATCH] fix #792 --- .../api/casting/eval/CastingEnvironment.java | 39 +++++++++++++------ .../actions/selectors/OpGetEntitiesBy.kt | 3 +- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java index 6eaaf765ec..9157063a97 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java @@ -57,11 +57,14 @@ public static void addCreateEventListener(BiConsumer listener) { - createEventListeners.add((env, data) -> {listener.accept(env);}); + createEventListeners.add((env, data) -> { + listener.accept(env); + }); } private boolean createEventTriggered = false; @@ -77,7 +80,8 @@ public final void triggerCreateEvent(CompoundTag userData) { protected final ServerLevel world; - protected Map, @NotNull CastingEnvironmentComponent> componentMap = new HashMap<>(); + protected Map, @NotNull CastingEnvironmentComponent> componentMap = + new HashMap<>(); private final List postExecutions = new ArrayList<>(); private final List postCasts = new ArrayList<>(); @@ -104,16 +108,20 @@ public int maxOpCount() { *

* Implementations should NOT rely on this in general, use the methods on this class instead. * This is mostly for spells (flight, etc) + * * @deprecated as of build 0.11.1-7-pre-619 you are recommended to use {@link #getCastingEntity} */ - @Deprecated(since="0.11.1-7-pre-619") + @Deprecated(since = "0.11.1-7-pre-619") @Nullable public ServerPlayer getCaster() { return getCastingEntity() instanceof ServerPlayer sp ? sp : null; - }; + } + + ; /** * Gets the caster. Can be null if {@link #getCaster()} is also null + * * @return the entity casting */ @Nullable @@ -299,7 +307,12 @@ public final boolean isVecInAmbit(Vec3 vec) { } public final boolean isEntityInRange(Entity e) { - return (e instanceof Player && HexConfig.server().trueNameHasAmbit()) || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position())); + return isEntityInRange(e, false); + } + + public final boolean isEntityInRange(Entity e, boolean ignoreTruenameAmbit) { + boolean truenameCheat = !ignoreTruenameAmbit && (e instanceof Player && HexConfig.server().trueNameHasAmbit()); + return truenameCheat || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position())); } /** @@ -361,7 +374,8 @@ public InteractionHand getOtherHand() { */ protected abstract List getUsableStacks(StackDiscoveryMode mode); - protected List getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand, ServerPlayer caster) { + protected List getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand + , ServerPlayer caster) { return switch (mode) { case QUERY -> { var out = new ArrayList(); @@ -386,8 +400,8 @@ protected List getUsableStacksForPlayer(StackDiscoveryMode mode, @Nul // If we're casting from the main hand, try to pick from the slot one to the right of the selected slot // Otherwise, scan the hotbar left to right var anchorSlot = castingHand != InteractionHand.OFF_HAND - ? (caster.getInventory().selected + 1) % 9 - : 0; + ? (caster.getInventory().selected + 1) % 9 + : 0; for (int delta = 0; delta < 9; delta++) { @@ -440,7 +454,7 @@ protected List getPrimaryStacksForPlayer(InteractionHand castingHa secondaryItem = ItemStack.EMPTY.copy(); return List.of(new HeldItemInfo(secondaryItem, HexUtils.otherHand(castingHand)), new HeldItemInfo(primaryItem, - castingHand)); + castingHand)); } /** @@ -537,12 +551,15 @@ public boolean withdrawItem(Predicate stackOk, int count, boolean act /** * Attempt to replace the first stack found which matches the predicate with the stack to replace with. + * * @return whether it was successful. */ - public abstract boolean replaceItem(Predicate stackOk, ItemStack replaceWith, @Nullable InteractionHand hand); + public abstract boolean replaceItem(Predicate stackOk, ItemStack replaceWith, + @Nullable InteractionHand hand); - public boolean replaceItemForPlayer(Predicate stackOk, ItemStack replaceWith, @Nullable InteractionHand hand, ServerPlayer caster) { + public boolean replaceItemForPlayer(Predicate stackOk, ItemStack replaceWith, + @Nullable InteractionHand hand, ServerPlayer caster) { if (caster == null) return false; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/selectors/OpGetEntitiesBy.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/selectors/OpGetEntitiesBy.kt index c3366c9aca..e5af57ad77 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/selectors/OpGetEntitiesBy.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/selectors/OpGetEntitiesBy.kt @@ -36,8 +36,9 @@ class OpGetEntitiesBy(val checker: Predicate, val negate: Boolean) : Con } companion object { + // Ignore truename ambit to fix #792 so you can't slurp up all players in the whole world fun isReasonablySelectable(ctx: CastingEnvironment, e: Entity) = - ctx.isEntityInRange(e) && e.isAlive && !e.isSpectator + ctx.isEntityInRange(e, true) && e.isAlive && !e.isSpectator @JvmStatic fun isAnimal(e: Entity): Boolean = e is Animal || e is WaterAnimal