diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index e25e1e0d..a93a68c9 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -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") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinAnvilChunkLoader_FixAllocations.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinAnvilChunkLoader_FixAllocations.java new file mode 100644 index 00000000..16e0456e --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinAnvilChunkLoader_FixAllocations.java @@ -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 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); + } +}