diff --git a/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java b/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java deleted file mode 100644 index 2fc7e88e..00000000 --- a/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java +++ /dev/null @@ -1,7 +0,0 @@ -package me.cortex.voxy.client; - -import net.minecraft.world.chunk.WorldChunk; - -public interface ICheekyClientChunkManager { - WorldChunk voxy$cheekyGetChunk(int x, int z); -} diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientChunkManager.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientChunkManager.java index 568b880c..f5d749ea 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientChunkManager.java +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinClientChunkManager.java @@ -1,18 +1,34 @@ package me.cortex.voxy.client.mixin.minecraft; -import me.cortex.voxy.client.ICheekyClientChunkManager; +import me.cortex.voxy.client.config.VoxyConfig; +import me.cortex.voxy.common.world.service.VoxelIngestService; import net.minecraft.client.world.ClientChunkManager; +import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.WorldChunk; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientChunkManager.class) -public class MixinClientChunkManager implements ICheekyClientChunkManager { +public class MixinClientChunkManager { @Shadow volatile ClientChunkManager.ClientChunkMap chunks; - @Override - public WorldChunk voxy$cheekyGetChunk(int x, int z) { + @Unique + private WorldChunk voxy$cheekyGetChunk(int x, int z) { //This doesnt do the in range check stuff, it just gets the chunk at all costs return this.chunks.getChunk(this.chunks.getIndex(x, z)); } + + @Inject(method = "unload", at = @At("HEAD")) + public void voxy$captureChunkBeforeUnload(ChunkPos pos, CallbackInfo ci) { + if (VoxyConfig.CONFIG.ingestEnabled) { + var chunk = this.voxy$cheekyGetChunk(pos.x, pos.z); + if (chunk != null) { + VoxelIngestService.tryAutoIngestChunk(chunk); + } + } + } } diff --git a/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinRenderSectionManager.java b/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinRenderSectionManager.java index 81168bb6..6a0f814f 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinRenderSectionManager.java +++ b/src/main/java/me/cortex/voxy/client/mixin/sodium/MixinRenderSectionManager.java @@ -1,22 +1,12 @@ package me.cortex.voxy.client.mixin.sodium; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import me.cortex.voxy.client.ICheekyClientChunkManager; -import me.cortex.voxy.client.VoxyClientInstance; -import me.cortex.voxy.client.config.VoxyConfig; import me.cortex.voxy.client.core.IGetVoxyRenderSystem; import me.cortex.voxy.client.core.VoxyRenderSystem; -import me.cortex.voxy.common.world.WorldEngine; -import me.cortex.voxy.common.world.service.VoxelIngestService; -import me.cortex.voxy.commonImpl.VoxyCommon; -import me.cortex.voxy.commonImpl.WorldIdentifier; import net.caffeinemc.mods.sodium.client.gl.device.CommandList; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection; -import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionFlags; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager; import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo; import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkSectionPos; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -62,20 +52,6 @@ public class MixinRenderSectionManager { } }*/ - @Inject(method = "onChunkRemoved", at = @At("HEAD")) - private void injectIngest(int x, int z, CallbackInfo ci) { - //TODO: Am not quite sure if this is right - if (VoxyConfig.CONFIG.ingestEnabled) { - var cccm = (ICheekyClientChunkManager)this.level.getChunkManager(); - if (cccm != null) { - var chunk = cccm.voxy$cheekyGetChunk(x, z); - if (chunk != null) { - VoxelIngestService.tryAutoIngestChunk(chunk); - } - } - } - } - @Redirect(method = "updateSectionInfo", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/RenderSection;setInfo(Lnet/caffeinemc/mods/sodium/client/render/chunk/data/BuiltSectionInfo;)Z")) private boolean voxy$updateOnUpload(RenderSection instance, BuiltSectionInfo info) { boolean wasBuilt = instance.isBuilt();