|
5 | 5 | import com.google.common.collect.UnmodifiableIterator; |
6 | 6 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
7 | 7 | import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 8 | +import com.mojang.datafixers.util.Pair; |
| 9 | +import net.caffeinemc.mods.lithium.common.ai.useless_behaviors.LithiumEmptyBehavior; |
8 | 10 | import net.minecraft.world.entity.LivingEntity; |
9 | 11 | import net.minecraft.world.entity.ai.Brain; |
| 12 | +import net.minecraft.world.entity.ai.behavior.BehaviorControl; |
10 | 13 | import org.jspecify.annotations.Nullable; |
11 | 14 | import org.spongepowered.asm.mixin.Mixin; |
12 | 15 | import org.spongepowered.asm.mixin.injection.At; |
13 | 16 |
|
14 | 17 | import java.util.Iterator; |
15 | 18 |
|
16 | 19 | @Mixin(Brain.class) |
17 | | -public abstract class BrainMixin<E extends LivingEntity> { |
| 20 | +public abstract class BrainMixin<T extends LivingEntity> { |
18 | 21 |
|
19 | 22 | /** |
20 | 23 | * @author jcw780, 2No2Name |
21 | 24 | * @reason Prevent EMPTY_BEHAVIOR_SENTINEL from being added - those are what useless behaviors are replaced with. |
22 | 25 | */ |
23 | 26 | @WrapOperation(method = "addActivityAndRemoveMemoriesWhenStopped", |
24 | 27 | at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList;iterator()Lcom/google/common/collect/UnmodifiableIterator;")) |
25 | | - private UnmodifiableIterator<E> filterSentinels(ImmutableList<E> instance, Operation<UnmodifiableIterator<E>> original) { |
| 28 | + private <E extends Pair<Integer, ? extends BehaviorControl<? super T>>> UnmodifiableIterator<E> filterSentinels(ImmutableList<E> instance, Operation<UnmodifiableIterator<E>> original) { |
26 | 29 | Iterator<E> wrapped = original.call(instance); |
27 | 30 | return new AbstractIterator<>() { |
28 | 31 | @Override |
29 | 32 | protected @Nullable E computeNext() { |
30 | | - if (wrapped.hasNext()) { |
31 | | - return wrapped.next(); |
| 33 | + while (wrapped.hasNext()) { |
| 34 | + E next = wrapped.next(); |
| 35 | + if (next.getSecond() != LithiumEmptyBehavior.EMPTY_BEHAVIOR_SENTINEL) { |
| 36 | + return next; |
| 37 | + } |
32 | 38 | } |
33 | 39 | return this.endOfData(); |
34 | 40 | } |
|
0 commit comments