mirror of
https://github.com/GTNewHorizons/lwjgl3ify.git
synced 2026-11-20 04:09:59 +00:00
Make GTNH work with Java 11:
- Add a javax.xml.bind -> jakarta.xml.bind remapper and shadow in the library - Update commons-lang3 to fix a loading crash - Fix UnsafeHacks on static fields - Add more enums to add extensibility to - Workaround java 8 miscompilation of lambda fields in interfaces
This commit is contained in:
1 parent
67eb934178
commit
3ff3d0a2cc
10 files changed
+154
-31
No files matched your search
@@ -47,6 +47,12 @@ tasks.register("runComparisonTool", JavaExec) {
|
||||
maxHeapSize = "2G"
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks.named("relocateShadowJar").configure {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
def lwjgl2Zips = configurations.named("lwjglMcCompileClasspath").get().resolve().findAll {!it.name.contains("natives") && !it.path.contains("net.java.j")}
|
||||
def lwjgl3Zips = configurations.named("lwjglModClasspath").get().resolve().findAll {!it.name.contains("natives")}
|
||||
|
||||
+4
-1
@@ -122,6 +122,7 @@ propertyDefaultIfUnset("modrinthProjectId", "")
|
||||
propertyDefaultIfUnset("modrinthRelations", "")
|
||||
propertyDefaultIfUnset("curseForgeProjectId", "")
|
||||
propertyDefaultIfUnset("curseForgeRelations", "")
|
||||
propertyDefaultIfUnset("minimizeShadowedDependencies", true)
|
||||
|
||||
String javaSourceDir = "src/main/java/"
|
||||
String scalaSourceDir = "src/main/scala/"
|
||||
@@ -623,7 +624,9 @@ if (usesShadowedDependencies.toBoolean()) {
|
||||
attributes(getManifestAttributes())
|
||||
}
|
||||
|
||||
minimize() // This will only allow shading for actually used classes
|
||||
if (minimizeShadowedDependencies.toBoolean()) {
|
||||
minimize() // This will only allow shading for actually used classes
|
||||
}
|
||||
configurations = [
|
||||
project.configurations.shadowImplementation,
|
||||
project.configurations.shadowCompile,
|
||||
|
||||
@@ -21,6 +21,9 @@ dependencies {
|
||||
patchedMinecraft('org.ow2.asm:asm-deprecated:7.1')
|
||||
}
|
||||
|
||||
shadowImplementation("jakarta.xml.bind:jakarta.xml.bind-api:3.0.1")
|
||||
shadowImplementation("com.sun.xml.bind:jaxb-impl:3.0.2")
|
||||
|
||||
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.8:processor')
|
||||
implementation('com.gtnewhorizon:gtnhmixins:2.1.8')
|
||||
|
||||
|
||||
+4
-1
@@ -72,7 +72,10 @@ forceEnableMixins = true
|
||||
|
||||
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
|
||||
# responsibility check the licence and request permission for distribution, if required.
|
||||
usesShadowedDependencies = false
|
||||
usesShadowedDependencies = true
|
||||
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
|
||||
# their own classes, making the minimization unreliable.
|
||||
minimizeShadowedDependencies = false
|
||||
|
||||
|
||||
# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/java.text=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/java.util=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/jdk.internal.reflect=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED"
|
||||
],
|
||||
"formatVersion": 1,
|
||||
@@ -21,7 +22,7 @@
|
||||
"url": "https://maven.minecraftforge.net/"
|
||||
},
|
||||
{
|
||||
"name": "net.minecraft:launchwrapper:1.13",
|
||||
"name": "net.minecraft:launchwrapper:1.14",
|
||||
"url": "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
|
||||
},
|
||||
{
|
||||
@@ -48,10 +49,6 @@
|
||||
"name": "org.ow2.asm:asm-deprecated:7.1",
|
||||
"url": "https://maven.minecraftforge.net/"
|
||||
},
|
||||
{
|
||||
"name": "javax.xml.bind:jaxb-api:2.3.1",
|
||||
"url": "https://repo1.maven.org/maven2/"
|
||||
},
|
||||
{
|
||||
"name": "com.typesafe.akka:akka-actor_2.11:2.3.3",
|
||||
"url": "https://maven.minecraftforge.net/"
|
||||
@@ -103,7 +100,7 @@
|
||||
"name": "com.google.guava:guava:17.0"
|
||||
},
|
||||
{
|
||||
"name": "org.apache.commons:commons-lang3:3.3.2"
|
||||
"name": "org.apache.commons:commons-lang3:3.12.0"
|
||||
}
|
||||
],
|
||||
"mainClass": "net.minecraft.launchwrapper.Launch",
|
||||
|
||||
@@ -47,23 +47,47 @@ public class UnsafeHacks {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(Field field, Object object) {
|
||||
final long l = UNSAFE.objectFieldOffset(field);
|
||||
return (T) UNSAFE.getObject(object, l);
|
||||
if (object == null) {
|
||||
long offset = UNSAFE.staticFieldOffset(field);
|
||||
Object base = UNSAFE.staticFieldBase(field);
|
||||
return (T) UNSAFE.getObject(base, offset);
|
||||
} else {
|
||||
long offset = UNSAFE.objectFieldOffset(field);
|
||||
return (T) UNSAFE.getObject(object, offset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Field data, Object object, Object value) {
|
||||
long offset = UNSAFE.objectFieldOffset(data);
|
||||
UNSAFE.putObject(object, offset, value);
|
||||
if (object == null) {
|
||||
long offset = UNSAFE.staticFieldOffset(data);
|
||||
Object base = UNSAFE.staticFieldBase(data);
|
||||
UNSAFE.putObject(base, offset, value);
|
||||
} else {
|
||||
long offset = UNSAFE.objectFieldOffset(data);
|
||||
UNSAFE.putObject(object, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getIntField(Field f, Object obj) {
|
||||
long offset = UNSAFE.objectFieldOffset(f);
|
||||
return UNSAFE.getInt(obj, offset);
|
||||
public static int getIntField(Field field, Object object) {
|
||||
if (object == null) {
|
||||
long offset = UNSAFE.staticFieldOffset(field);
|
||||
Object base = UNSAFE.staticFieldBase(field);
|
||||
return UNSAFE.getInt(base, offset);
|
||||
} else {
|
||||
long offset = UNSAFE.objectFieldOffset(field);
|
||||
return UNSAFE.getInt(object, offset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setIntField(Field data, Object object, int value) {
|
||||
long offset = UNSAFE.objectFieldOffset(data);
|
||||
UNSAFE.putInt(object, offset, value);
|
||||
if (object == null) {
|
||||
long offset = UNSAFE.staticFieldOffset(data);
|
||||
Object base = UNSAFE.staticFieldBase(data);
|
||||
UNSAFE.putInt(base, offset, value);
|
||||
} else {
|
||||
long offset = UNSAFE.objectFieldOffset(data);
|
||||
UNSAFE.putInt(object, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we don't crash if any future versions change field names
|
||||
|
||||
@@ -32,9 +32,15 @@ public class Config {
|
||||
"vswe.stevesfactory.components.ComponentType",
|
||||
"vswe.stevesfactory.components.ConnectionSet",
|
||||
"vswe.stevesfactory.components.ConnectionOption",
|
||||
"ic2.core.init.InternalName",
|
||||
"gregtech.api.enums.Element",
|
||||
"gregtech.api.enums.OrePrefixes",
|
||||
"net.minecraft.client.audio.MusicTicker$MusicType",
|
||||
"org.bukkit.Material",
|
||||
"buildcraft.api.transport.IPipeTile.PipeType",
|
||||
"thaumcraft.common.entities.golems.EnumGolemType",
|
||||
};
|
||||
|
||||
|
||||
// TODO: Make this an actual config file :P
|
||||
public static List<String> EXTENSIBLE_ENUMS = Arrays.asList(DEFAULT_EXTENSIBLE_ENUMS);
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package me.eigenraven.lwjgl3ify.core;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.objectweb.asm.Handle;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
/**
|
||||
* Fixes a compilation bug of the java 8 compiler leading to the following exception at runtime:
|
||||
* cpw.mods.fml.common.LoaderException: java.lang.IncompatibleClassChangeError: Inconsistent constant pool data
|
||||
* in classfile for class com/gtnewhorizon/structurelib/alignment/IAlignmentLimits. Method
|
||||
* 'boolean lambda$static$0(net.minecraftforge.common.util.ForgeDirection,
|
||||
* com.gtnewhorizon.structurelib.alignment.enumerable.Rotation, com.gtnewhorizon.structurelib.alignment.enumerable.Flip)'
|
||||
* at index 77 is CONSTANT_MethodRef and should be CONSTANT_InterfaceMethodRef
|
||||
*/
|
||||
public class FixConstantPoolInterfaceMethodRefHelper {
|
||||
public boolean transform(ClassNode node) {
|
||||
if ((node.access & Opcodes.ACC_INTERFACE) == 0) {
|
||||
return false;
|
||||
}
|
||||
boolean changesMade = false;
|
||||
final String internalClassName = node.name;
|
||||
if (node.methods != null) {
|
||||
for (MethodNode method : node.methods) {
|
||||
if (method.instructions != null) {
|
||||
for (AbstractInsnNode insn : method.instructions) {
|
||||
changesMade |= validateInstruction(internalClassName, insn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return changesMade;
|
||||
}
|
||||
|
||||
private boolean validateInstruction(String internalClassName, AbstractInsnNode rawInsn) {
|
||||
AtomicBoolean changed = new AtomicBoolean(false);
|
||||
switch (rawInsn.getType()) {
|
||||
case AbstractInsnNode.INVOKE_DYNAMIC_INSN:
|
||||
final InvokeDynamicInsnNode insn = (InvokeDynamicInsnNode) rawInsn;
|
||||
insn.bsm = fixHandle(internalClassName, insn.bsm, changed);
|
||||
if (insn.bsmArgs != null) {
|
||||
for (int i = 0; i < insn.bsmArgs.length; i++) {
|
||||
final Object arg = insn.bsmArgs[i];
|
||||
if (arg instanceof Handle) {
|
||||
insn.bsmArgs[i] = fixHandle(internalClassName, (Handle) arg, changed);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// no-op
|
||||
break;
|
||||
}
|
||||
return changed.get();
|
||||
}
|
||||
|
||||
private Handle fixHandle(String internalClassName, Handle handle, AtomicBoolean changed) {
|
||||
if (!handle.isInterface() && handle.getOwner().equals(internalClassName)) {
|
||||
changed.set(true);
|
||||
return new Handle(handle.getTag(), handle.getOwner(), handle.getName(), handle.getDesc(), true);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
@@ -55,26 +55,29 @@ public class LwjglRedirectTransformer extends Remapper implements IClassTransfor
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
final String[] fromPrefixes = new String[] {
|
||||
"org/lwjgl/", "paulscode/sound/libraries/", "javax/xml/bind/",
|
||||
};
|
||||
|
||||
final String[] toPrefixes = new String[] {
|
||||
"org/lwjglx/", "me/eigenraven/lwjgl3ify/paulscode/sound/libraries/", "jakarta/xml/bind/",
|
||||
};
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
if (typeName == null) {
|
||||
return null;
|
||||
}
|
||||
calls++;
|
||||
final String OLD_PREFIX_GL = "org/lwjgl/";
|
||||
final String NEW_PREFIX_GL = "org/lwjglx/";
|
||||
final String OLD_PREFIX_PCS = "paulscode/sound/libraries/";
|
||||
final String NEW_PREFIX_PCS = "me/eigenraven/lwjgl3ify/paulscode/sound/libraries/";
|
||||
if (typeName.startsWith(OLD_PREFIX_GL)) {
|
||||
remaps++;
|
||||
final String newName = NEW_PREFIX_GL + typeName.substring(OLD_PREFIX_GL.length());
|
||||
return newName;
|
||||
} else if (typeName.startsWith(OLD_PREFIX_PCS)) {
|
||||
remaps++;
|
||||
return NEW_PREFIX_PCS + typeName.substring(OLD_PREFIX_PCS.length());
|
||||
} else {
|
||||
return typeName;
|
||||
for (int pfx = 0; pfx < fromPrefixes.length; pfx++) {
|
||||
if (typeName.startsWith(fromPrefixes[pfx])) {
|
||||
remaps++;
|
||||
final String newName = toPrefixes[pfx] + typeName.substring(fromPrefixes[pfx].length());
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
|
||||
private class Lwjgl3AwareException extends RuntimeException {}
|
||||
|
||||
@@ -11,7 +11,10 @@ import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
|
||||
public class UnfinalizeObjectHoldersTransformer implements IClassTransformer {
|
||||
// Keep ClassNode-operating transformers together for efficiency (don't read/write the class multiple times)
|
||||
final ExtensibleEnumTransformerHelper enumTransformer = new ExtensibleEnumTransformerHelper();
|
||||
final FixConstantPoolInterfaceMethodRefHelper cpiMethodRefTransformer =
|
||||
new FixConstantPoolInterfaceMethodRefHelper();
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass) {
|
||||
@@ -88,6 +91,14 @@ public class UnfinalizeObjectHoldersTransformer implements IClassTransformer {
|
||||
Lwjgl3ifyCoremod.LOGGER.info("Dynamicized enum {}={}", name, transformedName);
|
||||
}
|
||||
|
||||
final boolean ifaceMethodRefsTransformed = cpiMethodRefTransformer.transform(node);
|
||||
|
||||
if (ifaceMethodRefsTransformed) {
|
||||
workDone = true;
|
||||
Lwjgl3ifyCoremod.LOGGER.warn(
|
||||
"Fixed missing CONSTANT_InterfaceMethodRef miscompilation in {}={}", name, transformedName);
|
||||
}
|
||||
|
||||
if (workDone) {
|
||||
final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
|
||||
node.accept(writer);
|
||||
|
||||
Reference in new issue
Block a user