|
1 | 1 | package net.caffeinemc.mods.lithium.mixin.experimental.client_tick.entity.unused_brain; |
2 | 2 |
|
3 | | -import com.google.common.collect.ImmutableList; |
4 | 3 | import it.unimi.dsi.fastutil.objects.AbstractReference2ObjectFunction; |
5 | 4 | import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; |
6 | | -import net.caffeinemc.mods.lithium.common.util.collections.DummyList; |
| 5 | +import net.caffeinemc.mods.lithium.common.ai.brain.BrainExtended; |
7 | 6 | import net.minecraft.world.entity.ai.Brain; |
8 | 7 | import net.minecraft.world.entity.ai.memory.ExpirableValue; |
9 | 8 | import net.minecraft.world.entity.ai.memory.MemoryModuleType; |
10 | 9 | import org.spongepowered.asm.mixin.Final; |
11 | 10 | import org.spongepowered.asm.mixin.Mixin; |
12 | 11 | import org.spongepowered.asm.mixin.Mutable; |
13 | 12 | import org.spongepowered.asm.mixin.Shadow; |
14 | | -import org.spongepowered.asm.mixin.injection.At; |
15 | | -import org.spongepowered.asm.mixin.injection.Inject; |
16 | | -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
17 | 13 |
|
18 | | -import java.util.Collection; |
19 | 14 | import java.util.Map; |
20 | 15 | import java.util.Optional; |
21 | | -import java.util.function.Supplier; |
22 | 16 |
|
23 | | -@Mixin(value = Brain.class, priority = 1010) |
24 | | -//Apply after collections.brain.BrainMixin, which replaces the brain collections, deleting the default return value |
25 | | -public class BrainMixin { |
| 17 | +@Mixin(value = Brain.class) |
| 18 | +public class BrainMixin implements BrainExtended { |
26 | 19 |
|
27 | 20 | @Mutable |
28 | 21 | @Shadow |
29 | 22 | @Final |
30 | 23 | private Map<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memories; |
31 | 24 |
|
32 | 25 |
|
33 | | - @Inject( |
34 | | - method = "<init>(Ljava/util/Collection;Ljava/util/Collection;Lcom/google/common/collect/ImmutableList;Ljava/util/function/Supplier;)V", |
35 | | - at = @At("RETURN") |
36 | | - ) |
37 | | - private void pretendMemoryTypeRegisteredInDummyBrain(Collection<?> memories, Collection<?> sensors, ImmutableList<?> memoryEntries, Supplier<?> codecSupplier, CallbackInfo ci) { |
38 | | - if (memories instanceof DummyList<?>) { |
39 | | - if (this.memories instanceof AbstractReference2ObjectFunction<?, ?> memoryCollection) { |
40 | | - //noinspection unchecked |
41 | | - ((AbstractReference2ObjectFunction<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>>) memoryCollection).defaultReturnValue(Optional.empty()); |
42 | | - } else { |
43 | | - Reference2ObjectOpenHashMap<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memoryCollection = new Reference2ObjectOpenHashMap<>(this.memories); |
44 | | - memoryCollection.defaultReturnValue(Optional.empty()); |
45 | | - this.memories = memoryCollection; |
46 | | - } |
47 | | - |
| 26 | + @Override |
| 27 | + public void lithium$pretendAllMemoryTypesRegistered() { |
| 28 | + if (this.memories instanceof AbstractReference2ObjectFunction<?, ?> memoryCollection) { |
| 29 | + //noinspection unchecked |
| 30 | + ((AbstractReference2ObjectFunction<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>>) memoryCollection).defaultReturnValue(Optional.empty()); |
| 31 | + } else { |
| 32 | + Reference2ObjectOpenHashMap<MemoryModuleType<?>, Optional<? extends ExpirableValue<?>>> memoryCollection = new Reference2ObjectOpenHashMap<>(this.memories); |
| 33 | + memoryCollection.defaultReturnValue(Optional.empty()); |
| 34 | + this.memories = memoryCollection; |
48 | 35 | } |
49 | 36 | } |
50 | 37 |
|
|
0 commit comments