aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/lodmod/mixin
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-03 12:29:09 +0200
committermakamys <makamys@outlook.com>2022-06-03 12:29:09 +0200
commitd5b0ec39fda8bc53ecb44ff491eba6e0b096b296 (patch)
treeb3f77eda80638e22b239f44e46793db247351174 /src/main/java/makamys/lodmod/mixin
parent310007e1395cca1a0147c84fd7aa695592285be3 (diff)
downloadNeodymium-d5b0ec39fda8bc53ecb44ff491eba6e0b096b296.tar.gz
Neodymium-d5b0ec39fda8bc53ecb44ff491eba6e0b096b296.tar.bz2
Neodymium-d5b0ec39fda8bc53ecb44ff491eba6e0b096b296.zip
Make it work with fast render
Diffstat (limited to 'src/main/java/makamys/lodmod/mixin')
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java14
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinTessellator.java14
-rw-r--r--src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java2
3 files changed, 26 insertions, 4 deletions
diff --git a/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java b/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
index 196e809..39b435e 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinRenderGlobal.java
@@ -1,16 +1,22 @@
package makamys.lodmod.mixin;
+import java.nio.IntBuffer;
+
+import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import makamys.lodmod.LODMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.entity.Entity;
@Mixin(RenderGlobal.class)
abstract class MixinRenderGlobal {
@@ -25,6 +31,14 @@ abstract class MixinRenderGlobal {
}
}
+ // for OptiFine's Fast Render option
+ @Redirect(method = "renderSortedRenderersFast", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallLists(Ljava/nio/IntBuffer;)V"), remap=false)
+ private void redirectRenderAllRenderLists(IntBuffer buffer) {
+ if(!LODMod.isActive() || (LODMod.isActive() && LODMod.renderer.renderWorld)) {
+ GL11.glCallLists(buffer);
+ }
+ }
+
@Inject(method = "renderSortedRenderers", at = @At(value = "HEAD"))
public void preRenderSortedRenderers(int startRenderer, int numRenderers, int renderPass, double partialTickTime, CallbackInfoReturnable cir) {
if(LODMod.isActive()) {
diff --git a/src/main/java/makamys/lodmod/mixin/MixinTessellator.java b/src/main/java/makamys/lodmod/mixin/MixinTessellator.java
index 12eb1ce..d791ba9 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinTessellator.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinTessellator.java
@@ -6,11 +6,13 @@ import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
+import makamys.lodmod.LODMod;
import makamys.lodmod.ducks.ITessellator;
import makamys.lodmod.renderer.ChunkMesh;
import makamys.lodmod.renderer.MeshQuad;
import makamys.lodmod.renderer.MeshQuad.QuadPlaneComparator;
import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.WorldRenderer;
@Mixin(Tessellator.class)
abstract class MixinTessellator implements ITessellator {
@@ -54,7 +56,7 @@ abstract class MixinTessellator implements ITessellator {
}
}*/
- public ChunkMesh toChunkMesh(int pass) {
+ public ChunkMesh toChunkMesh(int pass, WorldRenderer wr) {
if(this.vertexCount % 4 != 0) {
System.out.println("Error: Vertex count is not a multiple of 4");
return null;
@@ -72,8 +74,12 @@ abstract class MixinTessellator implements ITessellator {
List<Byte> bVs = new ArrayList<>();
List<Integer> cs = new ArrayList<>();
+ int xOffset = wr.posX;
+ int yOffset = wr.posY;
+ int zOffset = wr.posZ;
+
for(int quadI = 0; quadI < this.vertexCount / 4; quadI++) {
- MeshQuad quad = new MeshQuad(rawBuffer, quadI * 32, new ChunkMesh.Flags(hasTexture, hasBrightness, hasColor, hasNormals));
+ MeshQuad quad = new MeshQuad(rawBuffer, quadI * 32, new ChunkMesh.Flags(hasTexture, hasBrightness, hasColor, hasNormals), xOffset, yOffset, zOffset);
/*if(quad.bUs[0] == quad.bUs[1] && quad.bUs[1] == quad.bUs[2] && quad.bUs[2] == quad.bUs[3] && quad.bUs[3] == quad.bVs[0] && quad.bVs[0] == quad.bVs[1] && quad.bVs[1] == quad.bVs[2] && quad.bVs[2] == quad.bVs[3] && quad.bVs[3] == 0) {
quad.deleted = true;
}*/
@@ -118,9 +124,11 @@ abstract class MixinTessellator implements ITessellator {
totalSimplifiedQuadCount += quadCount;
//System.out.println("simplified quads " + totalOriginalQuadCount + " -> " + totalSimplifiedQuadCount + " (ratio: " + ((float)totalSimplifiedQuadCount / (float)totalOriginalQuadCount) + ") totalMergeCountByPlane: " + Arrays.toString(totalMergeCountByPlane));
+ LODMod.debugHookToChunkMeshEnd();
+
if(quadCount > 0) {
return new ChunkMesh(
- (int)(-xOffset / 16), (int)(-yOffset / 16), (int)(-zOffset / 16),
+ (int)(xOffset / 16), (int)(yOffset / 16), (int)(zOffset / 16),
new ChunkMesh.Flags(hasTexture, hasBrightness, hasColor, hasNormals),
quadCount, quads, pass);
} else {
diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
index 8e36241..eba0a5e 100644
--- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
+++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java
@@ -97,7 +97,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer {
private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) {
if(LODMod.isActive() && !LODMod.disableChunkMeshes) {
if(chunkMeshes != null) {
- chunkMeshes.add(((ITessellator)Tessellator.instance).toChunkMesh(pass));
+ chunkMeshes.add(((ITessellator)Tessellator.instance).toChunkMesh(pass, WorldRenderer.class.cast(this)));
}
}
}