diff --git a/src/main/java/net/gensokyoreimagined/nitori/mixin/alloc/chunk_ticking/ServerChunkManagerMixin.java b/src/main/java/net/gensokyoreimagined/nitori/mixin/alloc/chunk_ticking/ServerChunkManagerMixin.java index efa03c8..80005d2 100644 --- a/src/main/java/net/gensokyoreimagined/nitori/mixin/alloc/chunk_ticking/ServerChunkManagerMixin.java +++ b/src/main/java/net/gensokyoreimagined/nitori/mixin/alloc/chunk_ticking/ServerChunkManagerMixin.java @@ -14,40 +14,40 @@ // along with this program. If not, see . package net.gensokyoreimagined.nitori.mixin.alloc.chunk_ticking; -//import net.minecraft.server.level.ChunkHolder; -//import net.minecraft.server.level.ServerChunkCache; -//import org.spongepowered.asm.mixin.Mixin; -//import org.spongepowered.asm.mixin.injection.At; -//import org.spongepowered.asm.mixin.injection.Inject; -//import org.spongepowered.asm.mixin.injection.Redirect; -//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -// -//import java.util.ArrayList; -//import java.util.function.BooleanSupplier; -// -//@Mixin(ServerChunkCache.class) -//public class ServerChunkManagerMixin { -// private final ArrayList cachedChunkList = new ArrayList<>(); -// -// @Redirect( -// method = "tickChunks()V", -// at = @At( -// value = "INVOKE", -// target = "Lcom/google/common/collect/Lists;newArrayListWithCapacity(I)Ljava/util/ArrayList;", -// remap = false -// ) -// ) -// private ArrayList redirectChunksListClone(int initialArraySize) { -// ArrayList list = this.cachedChunkList; -// list.clear(); // Ensure the list is empty before re-using it -// list.ensureCapacity(initialArraySize); -// -// return list; -// } -// -// @Inject(method = "tick(Ljava/util/function/BooleanSupplier;Z)V", at = @At("HEAD")) -// private void preTick(BooleanSupplier shouldKeepTicking, boolean tickChunks, CallbackInfo ci) { -// // Ensure references aren't leaked through this list -// this.cachedChunkList.clear(); -// } -//} \ No newline at end of file +import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ServerChunkCache; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.ArrayList; +import java.util.function.BooleanSupplier; + +@Mixin(ServerChunkCache.class) +public class ServerChunkManagerMixin { + private final ArrayList cachedChunkList = new ArrayList<>(); + + @Redirect( + method = "tickChunks()V", + at = @At( + value = "INVOKE", + target = "Lcom/google/common/collect/Lists;newArrayListWithCapacity(I)Ljava/util/ArrayList;", + remap = false + ) + ) + private ArrayList redirectChunksListClone(int initialArraySize) { + ArrayList list = this.cachedChunkList; + list.clear(); // Ensure the list is empty before re-using it + list.ensureCapacity(initialArraySize); + + return list; + } + + @Inject(method = "tick(Ljava/util/function/BooleanSupplier;Z)V", at = @At("HEAD")) + private void preTick(BooleanSupplier shouldKeepTicking, boolean tickChunks, CallbackInfo ci) { + // Ensure references aren't leaked through this list + this.cachedChunkList.clear(); + } +} \ No newline at end of file