diff --git a/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java b/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java new file mode 100644 index 00000000..2fc7e88e --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/ICheekyClientChunkManager.java @@ -0,0 +1,7 @@ +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 f5d749ea..36e6379f 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,7 +1,9 @@ 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.fabricmc.loader.api.FabricLoader; import net.minecraft.client.world.ClientChunkManager; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.chunk.WorldChunk; @@ -13,18 +15,21 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientChunkManager.class) -public class MixinClientChunkManager { +public class MixinClientChunkManager implements ICheekyClientChunkManager { + @Unique + private static final boolean BOBBY_INSTALLED = FabricLoader.getInstance().isModLoaded("bobby"); + @Shadow volatile ClientChunkManager.ClientChunkMap chunks; - @Unique - private WorldChunk voxy$cheekyGetChunk(int x, int z) { + @Override + public 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) { + if (VoxyConfig.CONFIG.ingestEnabled && BOBBY_INSTALLED) { 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 6a0f814f..481dde83 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,16 +1,23 @@ package me.cortex.voxy.client.mixin.sodium; +import me.cortex.voxy.client.ICheekyClientChunkManager; +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.service.VoxelIngestService; 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.RenderSectionManager; import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkSectionPos; +import net.minecraft.world.chunk.WorldChunk; import org.spongepowered.asm.mixin.Final; 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.Redirect; @@ -18,6 +25,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = RenderSectionManager.class, remap = false) public class MixinRenderSectionManager { + @Unique + private static final boolean BOBBY_INSTALLED = FabricLoader.getInstance().isModLoaded("bobby"); + @Shadow @Final private ClientWorld level; @Inject(method = "", at = @At("TAIL")) @@ -30,6 +40,20 @@ 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 && !BOBBY_INSTALLED) { + var cccm = (ICheekyClientChunkManager)this.level.getChunkManager(); + if (cccm != null) { + var chunk = cccm.voxy$cheekyGetChunk(x, z); + if (chunk != null) { + VoxelIngestService.tryAutoIngestChunk(chunk); + } + } + } + } + /* @Inject(method = "onChunkAdded", at = @At("HEAD")) private void voxy$trackChunkAdd(int x, int z, CallbackInfo ci) { diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index 67cc89bb..d2c27ce7 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -102,7 +102,7 @@ public class VoxelIngestService { if (section == null || !shouldIngestSection(section, chunk.getPos().x, i, chunk.getPos().z)) continue; //if (section.isEmpty()) continue; var pos = ChunkSectionPos.from(chunk.getPos(), i); - if (lightingProvider.getStatus(LightType.SKY, pos) != LightStorage.Status.LIGHT_AND_DATA || lightingProvider.getStatus(LightType.BLOCK, pos) != LightStorage.Status.LIGHT_AND_DATA) + if (lightingProvider.getStatus(LightType.SKY, pos) != LightStorage.Status.LIGHT_AND_DATA && lightingProvider.getStatus(LightType.BLOCK, pos) != LightStorage.Status.LIGHT_AND_DATA) continue; gotLighting = true; }