Move chunk ingest into client chunk manager

This commit is contained in:
mcrcortex
2025-06-23 22:22:40 +10:00
parent b8ede978c2
commit 90a6765e8a
3 changed files with 20 additions and 35 deletions

View File

@@ -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);
}

View File

@@ -1,18 +1,34 @@
package me.cortex.voxy.client.mixin.minecraft; 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.client.world.ClientChunkManager;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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) @Mixin(ClientChunkManager.class)
public class MixinClientChunkManager implements ICheekyClientChunkManager { public class MixinClientChunkManager {
@Shadow volatile ClientChunkManager.ClientChunkMap chunks; @Shadow volatile ClientChunkManager.ClientChunkMap chunks;
@Override @Unique
public WorldChunk voxy$cheekyGetChunk(int x, int z) { private WorldChunk voxy$cheekyGetChunk(int x, int z) {
//This doesnt do the in range check stuff, it just gets the chunk at all costs //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)); 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);
}
}
}
} }

View File

@@ -1,22 +1,12 @@
package me.cortex.voxy.client.mixin.sodium; 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.IGetVoxyRenderSystem;
import me.cortex.voxy.client.core.VoxyRenderSystem; 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.gl.device.CommandList;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection; 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.RenderSectionManager;
import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo; import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.util.math.ChunkSectionPos;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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")) @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) { private boolean voxy$updateOnUpload(RenderSection instance, BuiltSectionInfo info) {
boolean wasBuilt = instance.isBuilt(); boolean wasBuilt = instance.isBuilt();