Skip to content

Commit 0cfa571

Browse files
committed
cleaner ASM that spams less control flow exceptions
1 parent 8868dcf commit 0cfa571

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/main/java/mega/fluidlogged/internal/core/FluidLogRendererInjector.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424

2525
import com.falsepattern.lib.asm.ASMUtil;
2626
import com.falsepattern.lib.mapping.MappingManager;
27-
import com.falsepattern.lib.mapping.types.UniversalMethod;
27+
import com.falsepattern.lib.mapping.types.MappingType;
28+
import com.falsepattern.lib.mapping.types.NameType;
2829
import com.falsepattern.lib.turboasm.ClassNodeHandle;
2930
import com.falsepattern.lib.turboasm.TurboClassTransformer;
31+
import lombok.SneakyThrows;
3032
import lombok.val;
3133
import mega.fluidlogged.Tags;
3234
import org.jetbrains.annotations.NotNull;
@@ -75,29 +77,29 @@ public boolean shouldTransformClass(@NotNull String className, @NotNull ClassNod
7577
return "net.minecraft.client.renderer.WorldRenderer".equals(className);
7678
}
7779

80+
@SneakyThrows
7881
@Override
7982
public boolean transformClass(@NotNull String className, @NotNull ClassNodeHandle classNode) {
8083
val cn = classNode.getNode();
8184
if (cn == null) {
8285
return false;
8386
}
87+
val type = ASMUtil.discoverClassMappingType(cn);
88+
val block = MappingManager.classForName(NameType.Regular, MappingType.MCP, "net.minecraft.block.Block");
89+
val blockMethod = block.getMethod(MappingType.MCP, "getRenderBlockPass", "()I");
90+
val blockClassNameInternal = block.internalName().get(type);
91+
val blockMethodName = blockMethod.name().get(type);
92+
val blockMethodDesc = blockMethod.descriptor().get(type);
8493
val method = ASMUtil.findMethodFromMCP(cn, "updateRenderer", "(Lnet/minecraft/entity/EntityLivingBase;)V", false);
8594
val iter = method.instructions.iterator();
8695
while (iter.hasNext()) {
8796
val insn = iter.next();
8897
if (!(insn instanceof MethodInsnNode))
8998
continue;
9099
val mInsn = (MethodInsnNode) insn;
91-
UniversalMethod uMethod;
92-
try {
93-
uMethod = MappingManager.getMethod(mInsn);
94-
} catch (ClassNotFoundException | NoSuchMethodException ignored) {
95-
continue;
96-
}
97-
if (!"net.minecraft.block.Block".equals(uMethod.parent().regularName().mcp())) {
98-
continue;
99-
}
100-
if (!"getRenderBlockPass".equals(uMethod.name().mcp())) {
100+
if (!blockClassNameInternal.equals(mInsn.owner) ||
101+
!blockMethodName.equals(mInsn.name) ||
102+
!blockMethodDesc.equals(mInsn.desc)) {
101103
continue;
102104
}
103105
iter.previous();

0 commit comments

Comments
 (0)