Skip to content

Commit 2e4d53f

Browse files
committed
fix #792
1 parent 2428d83 commit 2e4d53f

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Common/src/main/java/at/petrak/hexcasting/api/casting/eval/CastingEnvironment.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ public static void addCreateEventListener(BiConsumer<CastingEnvironment, Compoun
5757

5858
/**
5959
* Add a listener that will be called whenever a new CastingEnvironment is created (legacy).
60+
*
6061
* @deprecated replaced by {@link #addCreateEventListener(BiConsumer)}
6162
*/
6263
@Deprecated(since = "0.11.0-pre-660")
6364
public static void addCreateEventListener(Consumer<CastingEnvironment> listener) {
64-
createEventListeners.add((env, data) -> {listener.accept(env);});
65+
createEventListeners.add((env, data) -> {
66+
listener.accept(env);
67+
});
6568
}
6669

6770
private boolean createEventTriggered = false;
@@ -77,7 +80,8 @@ public final void triggerCreateEvent(CompoundTag userData) {
7780

7881
protected final ServerLevel world;
7982

80-
protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap = new HashMap<>();
83+
protected Map<CastingEnvironmentComponent.Key<?>, @NotNull CastingEnvironmentComponent> componentMap =
84+
new HashMap<>();
8185
private final List<PostExecution> postExecutions = new ArrayList<>();
8286

8387
private final List<PostCast> postCasts = new ArrayList<>();
@@ -104,16 +108,20 @@ public int maxOpCount() {
104108
* <p>
105109
* Implementations should NOT rely on this in general, use the methods on this class instead.
106110
* This is mostly for spells (flight, etc)
111+
*
107112
* @deprecated as of build 0.11.1-7-pre-619 you are recommended to use {@link #getCastingEntity}
108113
*/
109-
@Deprecated(since="0.11.1-7-pre-619")
114+
@Deprecated(since = "0.11.1-7-pre-619")
110115
@Nullable
111116
public ServerPlayer getCaster() {
112117
return getCastingEntity() instanceof ServerPlayer sp ? sp : null;
113-
};
118+
}
119+
120+
;
114121

115122
/**
116123
* Gets the caster. Can be null if {@link #getCaster()} is also null
124+
*
117125
* @return the entity casting
118126
*/
119127
@Nullable
@@ -299,7 +307,12 @@ public final boolean isVecInAmbit(Vec3 vec) {
299307
}
300308

301309
public final boolean isEntityInRange(Entity e) {
302-
return (e instanceof Player && HexConfig.server().trueNameHasAmbit()) || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
310+
return isEntityInRange(e, false);
311+
}
312+
313+
public final boolean isEntityInRange(Entity e, boolean ignoreTruenameAmbit) {
314+
boolean truenameCheat = !ignoreTruenameAmbit && (e instanceof Player && HexConfig.server().trueNameHasAmbit());
315+
return truenameCheat || (this.isVecInWorld(e.position()) && this.isVecInRange(e.position()));
303316
}
304317

305318
/**
@@ -361,7 +374,8 @@ public InteractionHand getOtherHand() {
361374
*/
362375
protected abstract List<ItemStack> getUsableStacks(StackDiscoveryMode mode);
363376

364-
protected List<ItemStack> getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand, ServerPlayer caster) {
377+
protected List<ItemStack> getUsableStacksForPlayer(StackDiscoveryMode mode, @Nullable InteractionHand castingHand
378+
, ServerPlayer caster) {
365379
return switch (mode) {
366380
case QUERY -> {
367381
var out = new ArrayList<ItemStack>();
@@ -386,8 +400,8 @@ protected List<ItemStack> getUsableStacksForPlayer(StackDiscoveryMode mode, @Nul
386400
// If we're casting from the main hand, try to pick from the slot one to the right of the selected slot
387401
// Otherwise, scan the hotbar left to right
388402
var anchorSlot = castingHand != InteractionHand.OFF_HAND
389-
? (caster.getInventory().selected + 1) % 9
390-
: 0;
403+
? (caster.getInventory().selected + 1) % 9
404+
: 0;
391405

392406

393407
for (int delta = 0; delta < 9; delta++) {
@@ -440,7 +454,7 @@ protected List<HeldItemInfo> getPrimaryStacksForPlayer(InteractionHand castingHa
440454
secondaryItem = ItemStack.EMPTY.copy();
441455

442456
return List.of(new HeldItemInfo(secondaryItem, HexUtils.otherHand(castingHand)), new HeldItemInfo(primaryItem,
443-
castingHand));
457+
castingHand));
444458
}
445459

446460
/**
@@ -537,12 +551,15 @@ public boolean withdrawItem(Predicate<ItemStack> stackOk, int count, boolean act
537551

538552
/**
539553
* Attempt to replace the first stack found which matches the predicate with the stack to replace with.
554+
*
540555
* @return whether it was successful.
541556
*/
542-
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand);
557+
public abstract boolean replaceItem(Predicate<ItemStack> stackOk, ItemStack replaceWith,
558+
@Nullable InteractionHand hand);
543559

544560

545-
public boolean replaceItemForPlayer(Predicate<ItemStack> stackOk, ItemStack replaceWith, @Nullable InteractionHand hand, ServerPlayer caster) {
561+
public boolean replaceItemForPlayer(Predicate<ItemStack> stackOk, ItemStack replaceWith,
562+
@Nullable InteractionHand hand, ServerPlayer caster) {
546563
if (caster == null)
547564
return false;
548565

Common/src/main/java/at/petrak/hexcasting/common/casting/actions/selectors/OpGetEntitiesBy.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ class OpGetEntitiesBy(val checker: Predicate<Entity>, val negate: Boolean) : Con
3636
}
3737

3838
companion object {
39+
// Ignore truename ambit to fix #792 so you can't slurp up all players in the whole world
3940
fun isReasonablySelectable(ctx: CastingEnvironment, e: Entity) =
40-
ctx.isEntityInRange(e) && e.isAlive && !e.isSpectator
41+
ctx.isEntityInRange(e, true) && e.isAlive && !e.isSpectator
4142

4243
@JvmStatic
4344
fun isAnimal(e: Entity): Boolean = e is Animal || e is WaterAnimal

0 commit comments

Comments
 (0)