瀏覽代碼

Fix bugs

Fix #149
Fix #155
Danielshe 5 年之前
父節點
當前提交
3724a6db85

+ 10 - 20
src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java

@@ -31,25 +31,15 @@ import java.util.function.Supplier;
 
 public class DefaultCraftingCategory implements TransferRecipeCategory<DefaultCraftingDisplay> {
     
+    @Deprecated
     public static int getSlotWithSize(DefaultCraftingDisplay recipeDisplay, int num) {
-        if (recipeDisplay.getWidth() == 1) {
-            if (num == 1)
-                return 3;
-            if (num == 2)
-                return 6;
-        }
-        
-        if (recipeDisplay.getWidth() == 2) {
-            if (num == 2)
-                return 3;
-            if (num == 3)
-                return 4;
-            if (num == 4)
-                return 6;
-            if (num == 5)
-                return 7;
-        }
-        return num;
+        return getSlotWithSize(recipeDisplay, num, 3);
+    }
+    
+    public static int getSlotWithSize(DefaultCraftingDisplay recipeDisplay, int num, int craftingGridWidth) {
+        int x = num % recipeDisplay.getWidth();
+        int y = (num - x) / recipeDisplay.getWidth();
+        return craftingGridWidth * y + x;
     }
     
     @Override
@@ -88,7 +78,7 @@ public class DefaultCraftingCategory implements TransferRecipeCategory<DefaultCr
         for (int i = 0; i < input.size(); i++) {
             if (recipeDisplaySupplier.get() instanceof DefaultShapedDisplay) {
                 if (!input.get(i).isEmpty())
-                    slots.get(getSlotWithSize(recipeDisplaySupplier.get(), i)).setItemList(input.get(i));
+                    slots.get(getSlotWithSize(recipeDisplaySupplier.get(), i, 3)).setItemList(input.get(i));
             } else if (!input.get(i).isEmpty())
                 slots.get(i).setItemList(input.get(i));
         }
@@ -102,7 +92,7 @@ public class DefaultCraftingCategory implements TransferRecipeCategory<DefaultCr
         Point startPoint = new Point(bounds.getCenterX() - 58, bounds.getCenterY() - 27);
         RenderHelper.translatef(0, 0, 400);
         for (Integer slot : redSlots) {
-            int i = getSlotWithSize(display, slot);
+            int i = getSlotWithSize(display, slot, 3);
             int x = i % 3;
             int y = (i - x) / 3;
             DrawableHelper.fill(startPoint.x + 1 + x * 18, startPoint.y + 1 + y * 18, startPoint.x + 1 + x * 18 + 16, startPoint.y + 1 + y * 18 + 16, 822018048);

+ 1 - 1
src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java

@@ -44,7 +44,7 @@ public interface DefaultCraftingDisplay extends TransferRecipeDisplay {
         }
         for (int i = 0; i < getInput().size(); i++) {
             List<ItemStack> stacks = getInput().get(i);
-            list.set(DefaultCraftingCategory.getSlotWithSize(this, i), stacks);
+            list.set(DefaultCraftingCategory.getSlotWithSize(this, i, containerInfo.getCraftingWidth(container)), stacks);
         }
         return list;
     }

+ 3 - 1
src/main/java/me/shedaniel/rei/server/InputSlotCrafter.java

@@ -13,6 +13,7 @@ import net.minecraft.container.Container;
 import net.minecraft.container.Slot;
 import net.minecraft.entity.player.PlayerInventory;
 import net.minecraft.inventory.Inventory;
+import net.minecraft.item.Item;
 import net.minecraft.item.ItemStack;
 import net.minecraft.recipe.Ingredient;
 import net.minecraft.server.network.ServerPlayerEntity;
@@ -23,6 +24,7 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<Integer> {
     
@@ -54,7 +56,7 @@ public class InputSlotCrafter<C extends Inventory> implements RecipeGridAligner<
             this.containerInfo.populateRecipeFinder(craftingContainer, recipeFinder);
             DefaultedList<Ingredient> ingredients = DefaultedList.of();
             map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getKey)).forEach(entry -> {
-                ingredients.add(Ingredient.ofStacks(entry.getValue().toArray(new ItemStack[0])));
+                ingredients.add(Ingredient.ofItems(entry.getValue().stream().map(ItemStack::getItem).collect(Collectors.toList()).toArray(new Item[0])));
             });
             if (recipeFinder.findRecipe(ingredients, (IntList) null)) {
                 this.fillInputSlots(recipeFinder, ingredients, hasShift);