diff options
author | makamys <makamys@outlook.com> | 2022-06-30 08:44:54 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-30 08:52:58 +0200 |
commit | 362a3b7d50557a4b86d70b398d37a9c438ffa262 (patch) | |
tree | f973ec7c27d9adf31d19f49ed5055626568e4f15 | |
parent | 359c4b702d4327d92704201fc2977dbf9d179dd7 (diff) | |
download | Neodymium-362a3b7d50557a4b86d70b398d37a9c438ffa262.tar.gz Neodymium-362a3b7d50557a4b86d70b398d37a9c438ffa262.tar.bz2 Neodymium-362a3b7d50557a4b86d70b398d37a9c438ffa262.zip |
Update meshes on `updateRenderersSort`, too
Fixes incorrect water rendering
-rw-r--r-- | src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java | 29 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/renderer/NeoChunk.java | 33 |
2 files changed, 31 insertions, 31 deletions
diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java index a45257f..ad7b3d2 100644 --- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -1,6 +1,6 @@ package makamys.neodymium.mixin; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.spongepowered.asm.mixin.Mixin; @@ -9,6 +9,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.google.common.collect.Lists; + import makamys.neodymium.Neodymium; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.renderer.ChunkMesh; @@ -30,46 +32,39 @@ abstract class MixinWorldRenderer implements IWorldRenderer { public boolean needsUpdate; boolean savedDrawnStatus; - private boolean insideUpdateRenderer; public List<ChunkMesh> chunkMeshes; - @Inject(method = "updateRenderer", at = @At(value = "HEAD")) + @Inject(method = {"updateRenderer", "updateRendererSort"}, at = @At(value = "HEAD")) private void preUpdateRenderer(CallbackInfo ci) { saveDrawnStatus(); - insideUpdateRenderer = true; if(Neodymium.isActive()) { - if(needsUpdate) { - if(chunkMeshes != null) { - chunkMeshes.clear(); - } else { - chunkMeshes = new ArrayList<>(); - } + if(chunkMeshes != null) { + Collections.fill(chunkMeshes, null); } else { - chunkMeshes = null; + chunkMeshes = Lists.newArrayList(null, null); } } } - @Inject(method = "updateRenderer", at = @At(value = "RETURN")) + @Inject(method = {"updateRenderer", "updateRendererSort"}, at = @At(value = "RETURN")) private void postUpdateRenderer(CallbackInfo ci) { notifyIfDrawnStatusChanged(); - insideUpdateRenderer = false; if(Neodymium.isActive()) { if(chunkMeshes != null) { Neodymium.renderer.onWorldRendererPost(WorldRenderer.class.cast(this)); - chunkMeshes.clear(); + Collections.fill(chunkMeshes, null); } } } - @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) + @Inject(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I")) private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { - if(insideUpdateRenderer && Neodymium.isActive()) { + if(Neodymium.isActive()) { if(chunkMeshes != null) { - chunkMeshes.add(ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); + chunkMeshes.set(pass, ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); } } } diff --git a/src/main/java/makamys/neodymium/renderer/NeoChunk.java b/src/main/java/makamys/neodymium/renderer/NeoChunk.java index c95b2bb..305b84c 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoChunk.java +++ b/src/main/java/makamys/neodymium/renderer/NeoChunk.java @@ -38,21 +38,26 @@ public class NeoChunk { public void putChunkMeshes(int cy, List<ChunkMesh> newChunkMeshes) { for(int i = 0; i < 2; i++) { ChunkMesh newChunkMesh = newChunkMeshes.size() > i ? newChunkMeshes.get(i) : null; - if(chunkMeshes[cy * 2 + i] != null) { - if(newChunkMesh != null) { - // ??? why is this needed? - newChunkMesh.pass = i; - } - - renderer.removeMesh(chunkMeshes[cy * 2 + i]); - chunkMeshes[cy * 2 + i].destroy(); - } else { - region.meshes++; - } - chunkMeshes[cy * 2 + i] = newChunkMesh; + + if(newChunkMesh != null) { + if(chunkMeshes[cy * 2 + i] != null) { + if(newChunkMesh != null) { + // ??? why is this needed? + newChunkMesh.pass = i; + } + + renderer.removeMesh(chunkMeshes[cy * 2 + i]); + chunkMeshes[cy * 2 + i].destroy(); + } else { + region.meshes++; + } + chunkMeshes[cy * 2 + i] = newChunkMesh; + dirty = true; + } + } + if(dirty) { + Neodymium.renderer.neoChunkChanged(this); } - Neodymium.renderer.neoChunkChanged(this); - dirty = true; } public boolean hasChunkMeshes() { |