malte0811 4 жил өмнө
parent
commit
66069b6342

+ 9 - 29
common/src/main/java/malte0811/ferritecore/classloading/FastImmutableMapDefiner.java

@@ -1,53 +1,33 @@
 package malte0811.ferritecore.classloading;
 package malte0811.ferritecore.classloading;
 
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableMap;
 import malte0811.ferritecore.ducks.FastMapStateHolder;
 import malte0811.ferritecore.ducks.FastMapStateHolder;
-import net.minecraft.util.LazyLoadedValue;
 import net.minecraft.world.level.block.state.properties.Property;
 import net.minecraft.world.level.block.state.properties.Property;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 
 
 import java.io.InputStream;
 import java.io.InputStream;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.invoke.MethodType;
-import java.lang.reflect.Method;
+import java.util.function.Supplier;
 
 
 /**
 /**
  * Helper to define classes in the com.google.common.collect package without issues due to jar signing and classloaders
  * Helper to define classes in the com.google.common.collect package without issues due to jar signing and classloaders
  * (the second one only seems to be an issue on Fabric, but the first one is a problem on both)
  * (the second one only seems to be an issue on Fabric, but the first one is a problem on both)
  */
  */
 public class FastImmutableMapDefiner {
 public class FastImmutableMapDefiner {
-    private static final Logger LOGGER = LogManager.getLogger("FerriteCore - class definer");
     public static String GOOGLE_ACCESS_PREFIX = "/googleaccess/";
     public static String GOOGLE_ACCESS_PREFIX = "/googleaccess/";
     public static String GOOGLE_ACCESS_SUFFIX = ".class_manual";
     public static String GOOGLE_ACCESS_SUFFIX = ".class_manual";
 
 
-    private static final LazyLoadedValue<Definer> DEFINE_CLASS = new LazyLoadedValue<>(() -> {
+    private static final Supplier<Definer> DEFINE_CLASS = Suppliers.memoize(() -> {
         try {
         try {
-            // Try to create a Java 9+ style class definer
-            // These are all public methods, but just don't exist in Java 8
-            Method makePrivateLookup = MethodHandles.class.getMethod(
-                    "privateLookupIn", Class.class, MethodHandles.Lookup.class
+            MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(
+                    ImmutableMap.class, MethodHandles.lookup()
             );
             );
-            Object privateLookup = makePrivateLookup.invoke(null, ImmutableMap.class, MethodHandles.lookup());
-            Method defineClass = MethodHandles.Lookup.class.getMethod("defineClass", byte[].class);
-            LOGGER.info("Using Java 9+ class definer");
-            return (bytes, name) -> (Class<?>) defineClass.invoke(privateLookup, (Object) bytes);
-        } catch (Exception x) {
-            try {
-                // If that fails, try a Java 8 style definer
-                Method defineClass = ClassLoader.class.getDeclaredMethod(
-                        "defineClass", String.class, byte[].class, int.class, int.class
-                );
-                defineClass.setAccessible(true);
-                ClassLoader loader = ImmutableMap.class.getClassLoader();
-                LOGGER.info("Using Java 8 class definer");
-                return (bytes, name) -> (Class<?>) defineClass.invoke(loader, name, bytes, 0, bytes.length);
-            } catch (NoSuchMethodException e) {
-                // Fail if neither works
-                throw new RuntimeException(e);
-            }
+            return (bytes, name) -> privateLookup.defineClass(bytes);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
         }
         }
     });
     });
 
 
@@ -55,7 +35,7 @@ public class FastImmutableMapDefiner {
      * Creates a MethodHandle for the constructor of FastMapEntryImmutableMap which takes one argument, which has to be
      * Creates a MethodHandle for the constructor of FastMapEntryImmutableMap which takes one argument, which has to be
      * an instance FastMapStateHolder. This also handles the necessary classloader acrobatics.
      * an instance FastMapStateHolder. This also handles the necessary classloader acrobatics.
      */
      */
-    private static final LazyLoadedValue<MethodHandle> MAKE_IMMUTABLE_FAST_MAP = new LazyLoadedValue<>(() -> {
+    private static final Supplier<MethodHandle> MAKE_IMMUTABLE_FAST_MAP = Suppliers.memoize(() -> {
         try {
         try {
             // Load these in the app classloader!
             // Load these in the app classloader!
             defineInAppClassloader("com.google.common.collect.FerriteCoreEntrySetAccess");
             defineInAppClassloader("com.google.common.collect.FerriteCoreEntrySetAccess");

+ 4 - 0
common/src/main/java/malte0811/ferritecore/mixin/blockstatecache/VSArrayAccess.java

@@ -3,17 +3,21 @@ package malte0811.ferritecore.mixin.blockstatecache;
 import it.unimi.dsi.fastutil.doubles.DoubleList;
 import it.unimi.dsi.fastutil.doubles.DoubleList;
 import net.minecraft.world.phys.shapes.ArrayVoxelShape;
 import net.minecraft.world.phys.shapes.ArrayVoxelShape;
 import org.spongepowered.asm.mixin.Mixin;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Mutable;
 import org.spongepowered.asm.mixin.gen.Accessor;
 import org.spongepowered.asm.mixin.gen.Accessor;
 
 
 @Mixin(ArrayVoxelShape.class)
 @Mixin(ArrayVoxelShape.class)
 public interface VSArrayAccess {
 public interface VSArrayAccess {
     @Accessor("xs")
     @Accessor("xs")
+    @Mutable
     void setXPoints(DoubleList newPoints);
     void setXPoints(DoubleList newPoints);
 
 
     @Accessor("ys")
     @Accessor("ys")
+    @Mutable
     void setYPoints(DoubleList newPoints);
     void setYPoints(DoubleList newPoints);
 
 
     @Accessor("zs")
     @Accessor("zs")
+    @Mutable
     void setZPoints(DoubleList newPoints);
     void setZPoints(DoubleList newPoints);
 
 
     @Accessor("xs")
     @Accessor("xs")

+ 1 - 1
common/src/main/resources/ferritecore.blockstatecache.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.blockstatecache",
   "package": "malte0811.ferritecore.mixin.blockstatecache",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "client": [
   "client": [
   ],
   ],
   "injectors": {
   "injectors": {

+ 1 - 1
common/src/main/resources/ferritecore.dedupbakedquad.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.dedupbakedquad",
   "package": "malte0811.ferritecore.mixin.dedupbakedquad",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "injectors": {
   "injectors": {
     "defaultRequire": 1
     "defaultRequire": 1
   },
   },

+ 1 - 1
common/src/main/resources/ferritecore.dedupmultipart.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.dedupmultipart",
   "package": "malte0811.ferritecore.mixin.dedupmultipart",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "injectors": {
   "injectors": {
     "defaultRequire": 1
     "defaultRequire": 1
   },
   },

+ 1 - 1
common/src/main/resources/ferritecore.fastmap.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.fastmap",
   "package": "malte0811.ferritecore.mixin.fastmap",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "mixins": [
   "mixins": [
     "FastMapStateHolderMixin"
     "FastMapStateHolderMixin"
   ],
   ],

+ 1 - 1
common/src/main/resources/ferritecore.mrl.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.mrl",
   "package": "malte0811.ferritecore.mixin.mrl",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "client": [
   "client": [
     "ModelResourceLocationMixin",
     "ModelResourceLocationMixin",
     "ResourceLocationAccess"
     "ResourceLocationAccess"

+ 1 - 1
common/src/main/resources/ferritecore.predicates.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.predicates",
   "package": "malte0811.ferritecore.mixin.predicates",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "client": [
   "client": [
     "AndConditionMixin",
     "AndConditionMixin",
     "OrConditionMixin",
     "OrConditionMixin",

+ 2 - 2
fabric/src/main/resources/ferritecore.fabric.mixin.json

@@ -1,7 +1,7 @@
 {
 {
   "required": true,
   "required": true,
   "package": "malte0811.ferritecore.mixin.fabric",
   "package": "malte0811.ferritecore.mixin.fabric",
-  "compatibilityLevel": "JAVA_8",
+  "compatibilityLevel": "JAVA_16",
   "client": [
   "client": [
     "MinecraftMixin"
     "MinecraftMixin"
   ],
   ],
@@ -10,4 +10,4 @@
   },
   },
   "plugin": "malte0811.ferritecore.mixin.fabric.Config",
   "plugin": "malte0811.ferritecore.mixin.fabric.Config",
   "minVersion": "0.8"
   "minVersion": "0.8"
-}
+}