Skip to content

Commit

Permalink
regression testings pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiyou06 committed Jul 7, 2024
1 parent 4651de9 commit 5a9831e
Showing 1 changed file with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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<ChunkHolder> 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<ChunkHolder> redirectChunksListClone(int initialArraySize) {
ArrayList<ChunkHolder> 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();
}
}
//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<ChunkHolder> 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<ChunkHolder> redirectChunksListClone(int initialArraySize) {
// ArrayList<ChunkHolder> 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();
// }
//}

0 comments on commit 5a9831e

Please sign in to comment.