Selaa lähdekoodia

Fix crash on recent Quilt versions, closes #104

The stream returned by getResourceAsStream on those Quilt builds returns the
class bytes one at a time, rather than reading the full file in one operation.
malte0811 2 vuotta sitten
vanhempi
sitoutus
72cbdbd910

+ 7 - 5
Common/src/main/java/malte0811/ferritecore/classloading/FastImmutableMapDefiner.java

@@ -5,6 +5,7 @@ import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableMap;
 import malte0811.ferritecore.ducks.FastMapStateHolder;
 import net.minecraft.world.level.block.state.properties.Property;
+import org.apache.commons.io.IOUtils;
 
 import java.io.InputStream;
 import java.lang.invoke.MethodHandle;
@@ -62,12 +63,13 @@ public class FastImmutableMapDefiner {
     }
 
     private static void defineInAppClassloader(String name) throws Exception {
-        InputStream byteInput = FastImmutableMapDefiner.class.getResourceAsStream(
+        byte[] classBytes;
+        try (InputStream byteInput = FastImmutableMapDefiner.class.getResourceAsStream(
                 GOOGLE_ACCESS_PREFIX + name.replace('.', '/') + GOOGLE_ACCESS_SUFFIX
-        );
-        byte[] classBytes = new byte[byteInput.available()];
-        final int bytesRead = byteInput.read(classBytes);
-        Preconditions.checkState(bytesRead == classBytes.length);
+        )) {
+            Preconditions.checkNotNull(byteInput, "Failed to find class bytes for " + name);
+            classBytes = IOUtils.toByteArray(byteInput);
+        }
         Class<?> loaded = DEFINE_CLASS.get().define(classBytes, name);
         Preconditions.checkState(loaded.getClassLoader() == ImmutableMap.class.getClassLoader());
     }

+ 1 - 1
gradle.properties

@@ -21,4 +21,4 @@ quilt_stdlib_version=1.1.0-beta.3+1.18.2
 mod_name=FerriteCore
 mod_author=malte0811
 mod_id=ferritecore
-mod_version=5.0.2
+mod_version=5.0.3