collections.GoalSelectorMixin

This commit is contained in:
Taiyou06
2024-07-09 00:05:25 +03:00
parent ed6e029363
commit 123ffb0988
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package net.gensokyoreimagined.nitori.mixin.collections.goals;
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Set;
import java.util.function.Supplier;
@Mixin(GoalSelector.class)
public abstract class GoalSelectorMixin {
@Mutable
@Shadow
@Final
private Set<WrappedGoal> availableGoals;
/**
* Replace the goal set with an optimized collection type which performs better for iteration.
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void reinit(Supplier<ProfilerFiller> supplier, CallbackInfo ci) {
this.availableGoals = new ObjectLinkedOpenHashSet<>(this.availableGoals);
}
}

View File

@@ -48,6 +48,7 @@
"collections.entity_by_type.TypeFilterableListMixin",
"collections.chunk_tickets.SortedArraySetMixin",
"collections.block_entity_tickers.WorldChunkMixin",
"collections.goals.GoalSelectorMixin",
"world.block_entity_ticking.sleeping.WrappedBlockEntityTickInvokerAccessor",
"world.block_entity_ticking.sleeping.campfire.CampfireBlockEntityMixin",
"world.block_entity_ticking.sleeping.campfire.unlit.CampfireBlockEntityMixin",