Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize mteTESR #245

Merged
merged 2 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,18 @@ public boolean canRenderBreaking() {
public boolean hasFastRenderer() {
return true;
}

public boolean hasTESR() {
if (metaTileEntity == null) return false;
if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
return true;
}
for (EnumFacing side : EnumFacing.VALUES) {
CoverBehavior cover = metaTileEntity.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity) {
return true;
}
}
return false;
}
}
6 changes: 6 additions & 0 deletions src/main/java/gregtech/core/GTCETransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
classReader.accept(new TargetClassVisitor(classWriter, RegionRenderCacheBuilderVisitor.TARGET_METHOD, RegionRenderCacheBuilderVisitor::new), 0);
return classWriter.toByteArray();
}
case RenderChunkVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classReader.accept(new TargetClassVisitor(classWriter, RenderChunkVisitor.TARGET_METHOD, RenderChunkVisitor::new), 0);
return classWriter.toByteArray();
}
case EntityRendererVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/gregtech/core/hooks/RenderChunkHooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gregtech.core.hooks;

import gregtech.api.metatileentity.MetaTileEntityHolder;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;

import javax.annotation.Nullable;

public class RenderChunkHooks {
public static <T extends TileEntity> TileEntitySpecialRenderer<T> getRenderer(TileEntityRendererDispatcher renderer, @Nullable TileEntity tileEntityIn) {
if (tileEntityIn instanceof MetaTileEntityHolder && !((MetaTileEntityHolder) tileEntityIn).hasTESR()) {
return null;
}
return renderer.getRenderer(tileEntityIn);
}
}
33 changes: 33 additions & 0 deletions src/main/java/gregtech/core/visitors/RenderChunkVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gregtech.core.visitors;

import gregtech.core.util.ObfMapping;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class RenderChunkVisitor extends MethodVisitor implements Opcodes {
public static final String TARGET_CLASS_NAME = "net/minecraft/client/renderer/chunk/RenderChunk";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "func_178581_b", "(FFFLnet/minecraft/client/renderer/chunk/ChunkCompileTaskGenerator;)V");
private static final ObfMapping METHOD_GET_RENDERER = new ObfMapping(
"net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher",
"func_147546_a",
"(Lnet/minecraft/tileentity/TileEntity;)Lnet/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer;").toRuntime();
private static final ObfMapping METHOD_GET_RENDERER_HOOKS = new ObfMapping(
"gregtech/core/hooks/RenderChunkHooks",
"getRenderer",
"(Lnet/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher;Lnet/minecraft/tileentity/TileEntity;)Lnet/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer;");

public RenderChunkVisitor(MethodVisitor mv) {
super(ASM5, mv);
}


@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (opcode == INVOKEVIRTUAL && (METHOD_GET_RENDERER.matches(name, desc))) {
METHOD_GET_RENDERER_HOOKS.visitMethodInsn(this, INVOKESTATIC);
return;
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}

}