Explorar o código

Finally fixed the NPE

shedaniel %!s(int64=5) %!d(string=hai) anos
pai
achega
c57fb54e81

+ 1 - 1
gradle.properties

@@ -1,4 +1,4 @@
-mod_version=3.2.16
+mod_version=3.2.17
 minecraft_version=1.15-pre6
 yarn_version=1.15-pre6+build.1
 fabricloader_version=0.7.2+build.174

+ 0 - 2
src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java

@@ -35,8 +35,6 @@ public class DefaultCategoryHandler implements AutoTransferHandler {
         if (!(context.getRecipe() instanceof TransferRecipeDisplay))
             return Result.createNotApplicable();
         TransferRecipeDisplay recipe = (TransferRecipeDisplay) context.getRecipe();
-        if (!ContainerInfoHandler.isCategoryHandled(recipe.getRecipeCategory()))
-            return Result.createNotApplicable();
         AbstractContainerScreen<?> containerScreen = context.getContainerScreen();
         Container container = containerScreen.getContainer();
         ContainerInfo containerInfo = ContainerInfoHandler.getContainerInfo(recipe.getRecipeCategory(), container.getClass());

+ 9 - 4
src/main/java/me/shedaniel/rei/server/ContainerInfoHandler.java

@@ -12,11 +12,11 @@ import net.minecraft.util.Identifier;
 import java.util.Map;
 
 public class ContainerInfoHandler {
-    private static final Map<String, Map<Class<? extends Container>, ContainerInfo>> containerInfoMap = Maps.newHashMap();
+    private static final Map<String, Map<Class<? extends Container>, ContainerInfo>> containerInfoMap = Maps.newLinkedHashMap();
     
     public static void registerContainerInfo(Identifier category, ContainerInfo containerInfo) {
-        if (!containerInfoMap.containsKey(category))
-            containerInfoMap.put(category.toString(), Maps.newHashMap());
+        if (!containerInfoMap.containsKey(category.toString()))
+            containerInfoMap.put(category.toString(), Maps.newLinkedHashMap());
         containerInfoMap.get(category.toString()).put(containerInfo.getContainerClass(), containerInfo);
     }
     
@@ -25,6 +25,11 @@ public class ContainerInfoHandler {
     }
     
     public static ContainerInfo getContainerInfo(Identifier category, Class<?> containerClass) {
-        return isCategoryHandled(category) ? containerInfoMap.get(category.toString()).get(containerClass) : null;
+        if (!isCategoryHandled(category)) return null;
+        Map<Class<? extends Container>, ContainerInfo> infoMap = containerInfoMap.get(category.toString());
+        if (infoMap.containsKey(containerClass)) return infoMap.get(containerClass);
+        for (Map.Entry<Class<? extends Container>, ContainerInfo> entry : infoMap.entrySet())
+            if (entry.getKey().isAssignableFrom(containerClass)) return entry.getValue();
+        return null;
     }
 }