Skip to content

Commit

Permalink
Cleaned up some new code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harleyoc1 committed Feb 14, 2021
1 parent 26ce9d4 commit 6e3314f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
33 changes: 15 additions & 18 deletions src/main/java/lumien/chunkanimator/handler/AnimationHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.util.math.vector.Vector3i;
import penner.easing.*;

import javax.annotation.Nullable;
import java.util.WeakHashMap;

public class AnimationHandler
Expand All @@ -21,8 +22,7 @@ public AnimationHandler()
timeStamps = new WeakHashMap<>();
}

@SuppressWarnings("deprecation") // OptiFine doesn't give us a choice in using GlStateManager.translated
public void preRender(ChunkRenderDispatcher.ChunkRender renderChunk, MatrixStack matrixStack)
public void preRender(ChunkRenderDispatcher.ChunkRender renderChunk, @Nullable MatrixStack matrixStack)
{
if (timeStamps.containsKey(renderChunk))
{
Expand Down Expand Up @@ -106,19 +106,10 @@ public void preRender(ChunkRenderDispatcher.ChunkRender renderChunk, MatrixStack

switch (mode) {
case 0:
// OptiFine uses GlStateManger instead of MatrixStack, so if OptiFine is enabled we set matrix stack to null and use that instead.
if (matrixStack == null) {
GlStateManager.translated(0, -chunkY + getFunctionValue(timeDif, 0, chunkY, animationDuration), 0);
} else {
matrixStack.translate(0, -chunkY + getFunctionValue(timeDif, 0, chunkY, animationDuration), 0);
}
this.translate(matrixStack, 0, -chunkY + getFunctionValue(timeDif, 0, chunkY, animationDuration), 0);
break;
case 1:
if (matrixStack == null) {
GlStateManager.translated(0, 256 - chunkY - getFunctionValue(timeDif, 0, 256 - chunkY, animationDuration), 0);
} else {
matrixStack.translate(0, 256 - chunkY - getFunctionValue(timeDif, 0, 256 - chunkY, animationDuration), 0);
}
this.translate(matrixStack, 0, 256 - chunkY - getFunctionValue(timeDif, 0, 256 - chunkY, animationDuration), 0);
break;
case 3:
Direction chunkFacing = animationData.chunkFacing;
Expand All @@ -130,11 +121,7 @@ public void preRender(ChunkRenderDispatcher.ChunkRender renderChunk, MatrixStack

mod = -(200 - getFunctionValue(timeDif, 0, 200, animationDuration));

if (matrixStack == null) {
GlStateManager.translated(vec.getX() * mod, 0, vec.getZ() * mod);
} else {
matrixStack.translate(vec.getX() * mod, 0, vec.getZ() * mod);
}
this.translate(matrixStack, vec.getX() * mod, 0, vec.getZ() * mod);
}
break;
}
Expand All @@ -146,6 +133,16 @@ public void preRender(ChunkRenderDispatcher.ChunkRender renderChunk, MatrixStack
}
}

@SuppressWarnings("deprecation") // OptiFine doesn't give us a choice in using GlStateManager.translated
private void translate (@Nullable MatrixStack matrixStack, double x, double y, double z) {
// OptiFine uses GlStateManger instead of MatrixStack, so if OptiFine is enabled we set matrix stack to null and use that instead.
if (matrixStack == null) {
GlStateManager.translated(x, y, z);
} else {
matrixStack.translate(x, y, z);
}
}

private float getFunctionValue(float t, float b, float c, float d)
{
switch (ChunkAnimatorConfig.easingFunction.get())
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors="Lumien" #optional

modId="chunkanimator" #mandatory

version="${file.jarVersion}" #mandatory
version="1.2" #mandatory

displayName="Chunk Animator" #mandatory

Expand Down
15 changes: 10 additions & 5 deletions src/main/resources/transformer/WorldRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function initializeCoreMod() {

var api = Java.type('net.minecraftforge.coremod.api.ASMAPI');

var translatedMethod = "translated";
var translatedMethodObf = "func_227670_b_";
var preRenderChunkMethod = "preRenderChunk";

var chunkRenderParam = "Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$ChunkRender";
var matrixStackParam = "Lcom/mojang/blaze3d/matrix/MatrixStack";

var methods = classNode.methods;

for (m in methods)
Expand All @@ -27,20 +34,18 @@ function initializeCoreMod() {
for (t in instr)
{
var instruction = instr[t];
if (instruction instanceof MethodInsnNode && (instruction.name === "translate" || instruction.name === "func_227861_a_" || instruction.name === "translated" || instruction.name === "func_227670_b_"))
if (instruction instanceof MethodInsnNode && (instruction.name === "translate" || instruction.name === "func_227861_a_" || instruction.name === translatedMethod || instruction.name === translatedMethodObf))
{
// OptiFine uses GlStateManger.translated instead of MatrixStack.translate
var optifine = instruction.name === "translated" || instruction.name === "func_227670_b_";
var optifine = instruction.name === translatedMethod || instruction.name === translatedMethodObf;

code.insertBefore(instruction, new VarInsnNode(Opcodes.ALOAD, optifine ? 14 : 12));

if (!optifine) {
code.insertBefore(instruction, new VarInsnNode(Opcodes.ALOAD, 2));
code.insertBefore(instruction, new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "preRenderChunk", "(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$ChunkRender;Lcom/mojang/blaze3d/matrix/MatrixStack;)V", false));
} else {
code.insertBefore(instruction, new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "preRenderChunk", "(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$ChunkRender;)V", false));
}

code.insertBefore(instruction, new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, preRenderChunkMethod, "(" + chunkRenderParam + (!optifine ? ";" + matrixStackParam : "") + ";)V", false));
}
}
}
Expand Down

0 comments on commit 6e3314f

Please sign in to comment.