Skip to content

Commit

Permalink
Compatible with forge 1.16.5-36.1.35.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZekerZhayard committed Jul 17, 2021
1 parent 9934910 commit 361aa30
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OptiForge ([CurseForge](https://www.curseforge.com/minecraft/mc-mods/optiforge))

*Compatibility: (2021-03-23)*
 *OptiForge-0.5.5*
 *Forge-1.16.5-36.0.60 or newer version*
*Compatibility: (2021-07-17)*
 *OptiForge-0.5.6*
 *Forge-1.16.5-36.1.35 or newer version*
 *OptiFine-1.16.5-G8-pre9 or newer version*

## How to Use
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ task sourcesJar(type: Jar) {
attributes(attrs)
}
from sourceSets.main.allSource
archiveFileName = "${archivesBaseName}-${archiveVersion}-sources.${archiveExtension}"
archiveFileName = "${archivesBaseName}-${archiveVersion.get()}-sources.${archiveExtension.get()}"
}

artifacts {
Expand All @@ -123,10 +123,12 @@ processResources {
]
inputs.properties pros
from sourceSets.main.resources.srcDirs, {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
include "requiredmods.properties", "META-INF/mods.toml"
expand pros
}
from sourceSets.main.resources.srcDirs, {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
exclude "requiredmods.properties", "META-INF/mods.toml"
}
}
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=0.5.5
mod_version=0.5.6
# G8_pre9
optifine_version=7.8.9
minecraft_version=1.16.5
forge_version=36.0.60
forge_gradle_version=4.1.3
mcp_mappings=20210315-1.15.1
forge_version=36.1.35
forge_gradle_version=5.0.29
mcp_mappings=20210715-1.15.1
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case "`uname`" in
Darwin* )
darwin=true
;;
MINGW* )
MSYS* | MINGW* )
msys=true
;;
NONSTOP* )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package io.github.zekerzhayard.optiforge.asm.transformers.net.minecraft.client.renderer.texture;

import java.util.HashMap;
import java.util.Objects;

import cpw.mods.modlauncher.api.ITransformer;
import io.github.zekerzhayard.optiforge.asm.transformers.ITransformerImpl;
import io.github.zekerzhayard.optiforge.asm.utils.ASMUtils;
import net.minecraftforge.coremod.api.ASMAPI;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FrameNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.spongepowered.asm.util.Bytecode;

public class AtlasTextureTransformer implements ITransformer<ClassNode>, ITransformerImpl {
Expand Down Expand Up @@ -83,6 +94,118 @@ public ClassNode transform(ClassNode input) {
}
}

// https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/patches/minecraft/net/minecraft/client/renderer/texture/AtlasTexture.java.patch#L33-L34
//
// try (IResource iresource = p_229218_1_.func_199002_a(resourcelocation)) {
// NativeImage nativeimage = NativeImage.func_195713_a(iresource.func_199027_b());
// + TextureAtlasSprite customSprite = net.minecraftforge.client.ForgeHooksClient.loadTextureAtlasSprite(this, p_229218_1_, p_229218_2_, iresource, p_229218_3_, p_229218_4_, p_229218_6_, p_229218_7_, p_229218_5_, nativeimage);
// + if (customSprite != null) return customSprite;
// return new TextureAtlasSprite(this, p_229218_2_, p_229218_5_, p_229218_3_, p_229218_4_, p_229218_6_, p_229218_7_, nativeimage);
// } catch (RuntimeException runtimeexception) {
// field_147635_d.error("Unable to parse metadata from {}", resourcelocation, runtimeexception);
//

MethodNode loadSprite = Objects.requireNonNull(Bytecode.findMethod(input, ASMAPI.mapMethod("func_229218_a_"), "(Lnet/minecraft/resources/IResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;"));

LabelNode label_0 = new LabelNode();
LabelNode label_1 = new LabelNode();
LabelNode label_2 = new LabelNode();
LabelNode label_3 = new LabelNode();
LabelNode label_4 = new LabelNode();
LabelNode label_5 = new LabelNode();
LabelNode label_6 = new LabelNode();
LabelNode label_7 = new LabelNode();
LocalVariableNode iresource = Objects.requireNonNull(ASMUtils.findLocalVariable(loadSprite, "Lnet/minecraft/resources/IResource;", 0));
LocalVariableNode textureatlassprite = Objects.requireNonNull(ASMUtils.findLocalVariable(loadSprite, "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", 0));
LocalVariableNode runtimeexception = Objects.requireNonNull(ASMUtils.findLocalVariable(loadSprite, "Ljava/lang/RuntimeException;", 0));
LocalVariableNode customSprite = new LocalVariableNode("customSprite", "Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", null, label_0, textureatlassprite.end, textureatlassprite.index);
ASMUtils.insertLocalVariable(loadSprite, customSprite, loadSprite.localVariables.size());

HashMap<Integer, TryCatchBlockNode> tryCatchBlocks = new HashMap<>();
tryCatchBlocks.put(0, new TryCatchBlockNode(label_2, label_3, label_4, "java/lang/Throwable"));
TryCatchBlockNode tcbn0 = null;
for (int i = 0, len = loadSprite.tryCatchBlocks.size(); i < len; i++) {
TryCatchBlockNode tcbn = loadSprite.tryCatchBlocks.get(i);
if (tcbn.handler.equals(textureatlassprite.end) && tcbn.type != null && tcbn.type.equals("java/lang/Throwable")) {
tryCatchBlocks.put(i, new TryCatchBlockNode(tcbn.start, label_1, tcbn.handler, tcbn.type));
tcbn.start = label_7;
tcbn0 = tcbn;
} else if (tcbn0 != null && tcbn.end.equals(tcbn0.end) && tcbn.type == null) {
tryCatchBlocks.put(i, new TryCatchBlockNode(tcbn.start, label_1, tcbn.handler, null));
tcbn.start = label_7;
} else if (!tcbn.start.equals(textureatlassprite.end) && tcbn.handler.equals(iresource.end) && tcbn.type != null && tcbn.type.equals("java/lang/RuntimeException")) {
tryCatchBlocks.put(i, new TryCatchBlockNode(tcbn.start, label_6, tcbn.handler, tcbn.type));
tcbn.start = label_7;
} else if (!tcbn.start.equals(textureatlassprite.end) && tcbn.handler.equals(runtimeexception.end) && tcbn.type != null && tcbn.type.equals("java/io/IOException")) {
tryCatchBlocks.put(i, new TryCatchBlockNode(tcbn.start, label_6, tcbn.handler, tcbn.type));
tcbn.start = label_7;
}
}
for (int i = loadSprite.tryCatchBlocks.size(); i >= 0; i--) {
TryCatchBlockNode tcbn = tryCatchBlocks.get(i);
if (tcbn != null) {
loadSprite.tryCatchBlocks.add(i, tcbn);
}
}

for (AbstractInsnNode ain : loadSprite.instructions.toArray()) {
if (ain.getOpcode() == Opcodes.NEW) {
TypeInsnNode tin = (TypeInsnNode) ain;
if (tin.desc.equals("net/minecraft/client/renderer/texture/TextureAtlasSprite")) {
InsnList il = new InsnList();
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
il.add(new VarInsnNode(Opcodes.ALOAD, 2));
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index));
il.add(new VarInsnNode(Opcodes.ILOAD, 3));
il.add(new VarInsnNode(Opcodes.ILOAD, 4));
il.add(new VarInsnNode(Opcodes.ILOAD, 6));
il.add(new VarInsnNode(Opcodes.ILOAD, 7));
il.add(new VarInsnNode(Opcodes.ILOAD, 5));
il.add(new VarInsnNode(Opcodes.ALOAD, ASMUtils.findLocalVariableIndex(loadSprite, "Lnet/minecraft/client/renderer/texture/NativeImage;", 0)));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/minecraftforge/client/ForgeHooksClient", "loadTextureAtlasSprite", "(Lnet/minecraft/client/renderer/texture/AtlasTexture;Lnet/minecraft/resources/IResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;Lnet/minecraft/resources/IResource;IIIIILnet/minecraft/client/renderer/texture/NativeImage;)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", false));
il.add(new VarInsnNode(Opcodes.ASTORE, customSprite.index));

il.add(label_0);
il.add(new VarInsnNode(Opcodes.ALOAD, customSprite.index));
il.add(new JumpInsnNode(Opcodes.IFNULL, label_7));
il.add(new VarInsnNode(Opcodes.ALOAD, customSprite.index));
il.add(new VarInsnNode(Opcodes.ASTORE, customSprite.index + 1));

il.add(label_1);
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index));
il.add(new JumpInsnNode(Opcodes.IFNULL, label_6));
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index + 1));
il.add(new JumpInsnNode(Opcodes.IFNULL, label_5));

il.add(label_2);
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index));
il.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "net/minecraft/resources/IResource", "close", "()V", true));

il.add(label_3);
il.add(new JumpInsnNode(Opcodes.GOTO, label_6));

il.add(label_4);
il.add(new VarInsnNode(Opcodes.ASTORE, customSprite.index + 2));
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index + 1));
il.add(new VarInsnNode(Opcodes.ALOAD, customSprite.index + 2));
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Throwable", "addSuppressed", "(Ljava/lang/Throwable;)V", false));
il.add(new JumpInsnNode(Opcodes.GOTO, label_6));

il.add(label_5);
il.add(new VarInsnNode(Opcodes.ALOAD, iresource.index));
il.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "net/minecraft/resources/IResource", "close", "()V", true));

il.add(label_6);
il.add(new VarInsnNode(Opcodes.ALOAD, customSprite.index + 1));
il.add(new InsnNode(Opcodes.ARETURN));
il.add(label_7);

loadSprite.instructions.insertBefore(tin, il);
}
}
}

return input;
}
}

0 comments on commit 361aa30

Please sign in to comment.