diff --git a/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java b/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java index 0a8f0c63..b528dd26 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java +++ b/src/main/java/me/cortex/voxy/client/VoxyClientInstance.java @@ -31,6 +31,10 @@ public class VoxyClientInstance extends VoxyInstance { vworld = this.createWorld(SELECTOR.getBestSelectionOrCreate(world).createSectionStorageBackend()); ((IVoxyWorldSetter)world).setWorldEngine(vworld); this.importWrapper = new WorldImportWrapper(this.threadPool, vworld); + } else { + if (!this.activeWorlds.contains(vworld)) { + throw new IllegalStateException("World referenced does not exist in instance"); + } } return vworld; } diff --git a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java index 412968e4..2553714e 100644 --- a/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java +++ b/src/main/java/me/cortex/voxy/client/config/VoxyConfigScreenFactory.java @@ -3,6 +3,8 @@ package me.cortex.voxy.client.config; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; import me.cortex.voxy.client.core.IGetVoxyRenderSystem; +import me.cortex.voxy.commonImpl.IVoxyWorldGetter; +import me.cortex.voxy.commonImpl.IVoxyWorldSetter; import me.cortex.voxy.commonImpl.VoxyCommon; import me.shedaniel.clothconfig2.api.ConfigBuilder; import me.shedaniel.clothconfig2.api.ConfigCategory; @@ -36,13 +38,24 @@ public class VoxyConfigScreenFactory implements ModMenuApi { builder.setSavingRunnable(() -> { //After saving the core should be reloaded/reset - var world = MinecraftClient.getInstance().worldRenderer; - if (world != null && ON_SAVE_RELOAD) { + var worldRenderer = MinecraftClient.getInstance().worldRenderer; + var world = MinecraftClient.getInstance().world; + if (worldRenderer != null && world != null && ON_SAVE_RELOAD) { //Reload voxy - ((IGetVoxyRenderSystem)world).shutdownRenderer(); + ((IGetVoxyRenderSystem)worldRenderer).shutdownRenderer(); + + //This is a hack inserted for the client world thing + //TODO: FIXME: MAKE BETTER + var engine = ((IVoxyWorldGetter)world).getWorldEngine(); + if (engine != null) { + VoxyCommon.getInstance().stopWorld(engine); + } + ((IVoxyWorldSetter)world).setWorldEngine(null); + + VoxyCommon.shutdownInstance(); VoxyCommon.createInstance(); - ((IGetVoxyRenderSystem)world).createRenderer(); + ((IGetVoxyRenderSystem)worldRenderer).createRenderer(); } ON_SAVE_RELOAD = false; VoxyConfig.CONFIG.save(); @@ -71,6 +84,12 @@ public class VoxyConfigScreenFactory implements ModMenuApi { .setDefaultValue(DEFAULT.ingestEnabled) .build()); + category.addEntry(entryBuilder.startBooleanToggle(Text.translatable("voxy.config.general.rendering"), config.enableRendering) + .setTooltip(Text.translatable("voxy.config.general.rendering.tooltip")) + .setSaveConsumer(val -> {if (config.enableRendering != val) reload(); config.enableRendering = val;}) + .setDefaultValue(DEFAULT.enableRendering) + .build()); + category.addEntry(entryBuilder.startIntSlider(Text.translatable("voxy.config.general.subDivisionSize"), (int) config.subDivisionSize, 25, 256) .setTooltip(Text.translatable("voxy.config.general.subDivisionSize.tooltip")) .setSaveConsumer(val -> config.subDivisionSize = val) diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java index 863ccab6..262f8583 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/hierachical/NodeManager.java @@ -143,7 +143,7 @@ public class NodeManager { long pos = sectionResult.position; int nodeId = this.activeSectionMap.get(pos); if (nodeId == -1) { - Logger.error("Got geometry update for pos " + WorldEngine.pprintPos(pos) + " but it was not in active map, discarding!"); + Logger.warn("Got geometry update for pos " + WorldEngine.pprintPos(pos) + " but it was not in active map, discarding!"); sectionResult.free(); return; } @@ -988,7 +988,7 @@ public class NodeManager { if (childExistence == 0) { if (!this.topLevelNodes.contains(pos)) {//Top level nodes are special, as they can have a request with child existence of 0 for performance reasons - Logger.warn("Not creating a leaf request with existence mask of 0"); + Logger.warn("Not creating a leaf request with existence mask of 0 at pos", WorldEngine.pprintPos(pos)); this.nodeData.unmarkRequestInFlight(nodeId); this.invalidateNode(nodeId); return; diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java index 978b0712..925ca751 100644 --- a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinWorldRenderer.java @@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.rendering.VoxyRenderSystem; import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.world.WorldEngine; import me.cortex.voxy.commonImpl.IVoxyWorldGetter; +import me.cortex.voxy.commonImpl.IVoxyWorldSetter; import me.cortex.voxy.commonImpl.VoxyCommon; import me.cortex.voxy.commonImpl.VoxyInstance; import net.minecraft.client.render.*; @@ -50,7 +51,7 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem { @Unique private ClientWorld refCopy; @Inject(method = "setWorld", at = @At("HEAD")) - private void initVoxelCore(ClientWorld world, CallbackInfo ci) { + private void voxy$captureSetWorld(ClientWorld world, CallbackInfo ci) { this.refCopy = this.world; } @@ -65,6 +66,7 @@ public abstract class MixinWorldRenderer implements IGetVoxyRenderSystem { if (engine != null) { VoxyCommon.getInstance().stopWorld(engine); } + ((IVoxyWorldSetter)this.refCopy).setWorldEngine(null); } } 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 4c55a699..2d5e4b04 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,5 +1,6 @@ package me.cortex.voxy.client.mixin.sodium; +import me.cortex.voxy.client.VoxyClientInstance; import me.cortex.voxy.client.config.VoxyConfig; import me.cortex.voxy.commonImpl.VoxyCommon; import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager; @@ -20,7 +21,14 @@ public class MixinRenderSectionManager { //TODO: Am not quite sure if this is right var instance = VoxyCommon.getInstance(); if (instance != null && VoxyConfig.CONFIG.ingestEnabled) { - instance.getIngestService().enqueueIngest(this.level.getChunk(x, z), false); + var chunk = this.level.getChunk(x, z); + var world = chunk.getWorld(); + if (world instanceof ClientWorld cw) { + var engine = ((VoxyClientInstance)instance).getOrMakeRenderWorld(cw); + if (engine != null) { + instance.getIngestService().enqueueIngest(engine, chunk); + } + } } } } 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 b7cd3a9f..ce24b8b1 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 @@ -91,6 +91,9 @@ public class VoxelIngestService { } public void enqueueIngest(WorldEngine engine, WorldChunk chunk) { + if (!engine.isLive()) { + throw new IllegalStateException("Tried inserting chunk into WorldEngine that was not alive"); + } var lightingProvider = chunk.getWorld().getLightingProvider(); var blp = lightingProvider.get(LightType.BLOCK); var slp = lightingProvider.get(LightType.SKY); diff --git a/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java b/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java index 361aa4a6..d6a8a966 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java +++ b/src/main/java/me/cortex/voxy/commonImpl/mixin/minecraft/MixinWorld.java @@ -6,7 +6,10 @@ import me.cortex.voxy.commonImpl.IVoxyWorldGetter; import me.cortex.voxy.commonImpl.IVoxyWorldSetter; import me.cortex.voxy.commonImpl.VoxyCommon; import net.minecraft.world.World; +import net.minecraft.world.block.NeighborUpdater; +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; @@ -14,6 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(World.class) public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter { + @Shadow @Final protected NeighborUpdater neighborUpdater; @Unique private WorldEngine voxyWorld; @Override @@ -23,7 +27,7 @@ public class MixinWorld implements IVoxyWorldGetter, IVoxyWorldSetter { @Override public void setWorldEngine(WorldEngine engine) { - if (this.voxyWorld != null) { + if (engine != null && this.voxyWorld != null) { throw new IllegalStateException("WorldEngine not null"); } this.voxyWorld = engine;