diff options
author | makamys <makamys@outlook.com> | 2022-07-11 22:55:20 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-07-11 22:56:53 +0200 |
commit | acdc0adecd3c8d649cad97c6932fb7ba418721e6 (patch) | |
tree | 9606d944818016067c1709825c92977323b6bb48 /src/main/java/makamys/neodymium/mixin | |
parent | f26762ca0c6b7c1977f71ae24b3b011a658d7e53 (diff) | |
download | Neodymium-acdc0adecd3c8d649cad97c6932fb7ba418721e6.tar.gz Neodymium-acdc0adecd3c8d649cad97c6932fb7ba418721e6.tar.bz2 Neodymium-acdc0adecd3c8d649cad97c6932fb7ba418721e6.zip |
Be able to capture chunk meshes consisting of multiple tessellations
Start of fix for #5
Diffstat (limited to 'src/main/java/makamys/neodymium/mixin')
-rw-r--r-- | src/main/java/makamys/neodymium/mixin/MixinTessellator.java | 29 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java | 27 |
2 files changed, 54 insertions, 2 deletions
diff --git a/src/main/java/makamys/neodymium/mixin/MixinTessellator.java b/src/main/java/makamys/neodymium/mixin/MixinTessellator.java new file mode 100644 index 0000000..15f71da --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinTessellator.java @@ -0,0 +1,29 @@ +package makamys.neodymium.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import makamys.neodymium.ducks.ITessellator; +import makamys.neodymium.renderer.ChunkMesh; +import net.minecraft.client.renderer.Tessellator; + +@Mixin(Tessellator.class) +abstract class MixinTessellator implements ITessellator { + + private boolean nd$captureMeshes; + + @Inject(method = "draw", at = @At(value = "HEAD")) + private void preDraw(CallbackInfoReturnable<Integer> cir) { + if(nd$captureMeshes) { + ChunkMesh.preTessellatorDraw((Tessellator)(Object)this); + } + } + + @Override + public void enableMeshCapturing(boolean enable) { + nd$captureMeshes = enable; + } + +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java index 32b27a9..a794931 100644 --- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -13,6 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.google.common.collect.Lists; import makamys.neodymium.Neodymium; +import makamys.neodymium.ducks.ITessellator; import makamys.neodymium.ducks.IWorldRenderer; import makamys.neodymium.renderer.ChunkMesh; import makamys.neodymium.renderer.NeoRenderer; @@ -81,12 +82,34 @@ abstract class MixinWorldRenderer implements IWorldRenderer { } } + @Inject(method = "preRenderBlocks", at = @At("HEAD")) + private void prePreRenderBlocks(int pass, CallbackInfo ci) { + if(Neodymium.isActive()) { + ((ITessellator)Tessellator.instance).enableMeshCapturing(true); + ChunkMesh cm = new ChunkMesh((WorldRenderer)(Object)this, pass); + nd$chunkMeshes.set(pass, cm); + ChunkMesh.setCaptureTarget(cm); + } + } + @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(Neodymium.isActive()) { + /*if(Neodymium.isActive()) { if(nd$chunkMeshes != null) { - nd$chunkMeshes.set(pass, ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); + if(nd$chunkMeshes.get(pass) == null) { + nd$chunkMeshes.set(pass, ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this))); + } + nd$chunkMeshes.get(pass).addTessellatorData(Tessellator.instance); } + }*/ + } + + @Inject(method = "postRenderBlocks", at = @At("RETURN")) + private void postPostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { + if(Neodymium.isActive()) { + nd$chunkMeshes.get(pass).finishConstruction(); + ((ITessellator)Tessellator.instance).enableMeshCapturing(false); + ChunkMesh.setCaptureTarget(null); } } |