Skip to content

Commit

Permalink
Add AnvilChunkLoader to reducing allocations of MutableChunkCoordIntPair
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Dec 24, 2024
1 parent 25e7352 commit 7489be4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public enum Mixins {
.addMixinClasses(
"minecraft.MixinChunkCoordIntPair",
"minecraft.MixinWorld_FixAllocations",
"minecraft.MixinWorldClient_FixAllocations")
"minecraft.MixinWorldClient_FixAllocations",
"minecraft.MixinAnvilChunkLoader_FixAllocations")
.setApplyIf(() -> FixesConfig.fixTooManyAllocationsChunkPositionIntPair)),
FIX_TOO_MANY_ALLOCATIONS_CHUNK_POSITION_INT_PAIR_OPTIFINE_INCOMPAT(
new Builder("Stops MC from allocating too many ChunkPositionIntPair objects")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft;

import java.util.Set;

import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import com.mitchej123.hodgepodge.hax.LongChunkCoordIntPairSet;
import com.mitchej123.hodgepodge.mixins.interfaces.MutableChunkCoordIntPair;

@Mixin(AnvilChunkLoader.class)
public class MixinAnvilChunkLoader_FixAllocations {

@Shadow
private Set<ChunkCoordIntPair> pendingAnvilChunksCoordinates = new LongChunkCoordIntPairSet();

private final MutableChunkCoordIntPair reusableCCIP = (MutableChunkCoordIntPair) new ChunkCoordIntPair(0, 0);

@Redirect(method = "chunkExists", at = @At(value = "NEW", target = "Lnet/minecraft/world/ChunkCoordIntPair;"))
private ChunkCoordIntPair chunkExistsReusable(int i, int j) {
return (ChunkCoordIntPair) reusableCCIP.setChunkPos(i, j);
}
}

0 comments on commit 7489be4

Please sign in to comment.