Эх сурвалжийг харах

Merge branch 'pull/378' into 4.x

shedaniel 5 жил өмнө
parent
commit
51f291e118

+ 30 - 5
src/main/java/me/shedaniel/rei/api/EntryStack.java

@@ -32,7 +32,6 @@ import me.shedaniel.rei.api.widgets.Tooltip;
 import me.shedaniel.rei.impl.EmptyEntryStack;
 import me.shedaniel.rei.impl.FluidEntryStack;
 import me.shedaniel.rei.impl.ItemEntryStack;
-import me.shedaniel.rei.utils.CollectionUtils;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.client.resource.language.I18n;
@@ -43,15 +42,16 @@ import net.minecraft.item.ItemConvertible;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundTag;
 import net.minecraft.nbt.StringNbtReader;
-import net.minecraft.text.LiteralText;
+import net.minecraft.recipe.Ingredient;
 import net.minecraft.text.Text;
-import net.minecraft.util.Formatting;
 import net.minecraft.util.Identifier;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.registry.Registry;
 import org.jetbrains.annotations.ApiStatus;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
@@ -81,11 +81,36 @@ public interface EntryStack extends TextRepresentable {
     static EntryStack create(ItemStack stack) {
         return new ItemEntryStack(stack);
     }
-    
+
     static EntryStack create(ItemConvertible item) {
         return create(new ItemStack(item));
     }
-    
+
+    static List<EntryStack> create(Collection<ItemStack> stacks) {
+        List<EntryStack> result = new ArrayList<>(stacks.size());
+        for (ItemStack stack : stacks) {
+            result.add(create(stack));
+        }
+        return result;
+    }
+
+    static List<EntryStack> create(Ingredient ingredient) {
+        ItemStack[] matchingStacks = ingredient.getMatchingStacksClient();
+        List<EntryStack> result = new ArrayList<>(matchingStacks.length);
+        for (ItemStack matchingStack : matchingStacks) {
+            result.add(create(matchingStack));
+        }
+        return result;
+    }
+
+    static List<List<EntryStack>> create(List<Ingredient> ingredients) {
+        List<List<EntryStack>> result = new ArrayList<>(ingredients.size());
+        for (Ingredient ingredient : ingredients) {
+            result.add(create(ingredient));
+        }
+        return result;
+    }
+
     @ApiStatus.Internal
     static EntryStack readFromJson(JsonElement jsonElement) {
         try {

+ 1 - 7
src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java

@@ -52,13 +52,7 @@ public class DefaultCampfireDisplay implements RecipeDisplay {
     }
     
     public DefaultCampfireDisplay(DefaultedList<Ingredient> ingredients, ItemStack output, int cookTime) {
-        this.inputs = ingredients.stream().map(i -> {
-            List<EntryStack> entries = new ArrayList<>();
-            for (ItemStack stack : i.getMatchingStacksClient()) {
-                entries.add(EntryStack.create(stack));
-            }
-            return entries;
-        }).collect(Collectors.toList());
+        this.inputs = EntryStack.create(ingredients);
         this.output = Collections.singletonList(EntryStack.create(output));
         this.cookTime = cookTime;
     }

+ 1 - 1
src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java

@@ -56,7 +56,7 @@ public abstract class DefaultCookingDisplay implements TransferRecipeDisplay {
     
     public DefaultCookingDisplay(AbstractCookingRecipe recipe) {
         this.recipe = recipe;
-        this.input = CollectionUtils.map(recipe.getPreviewInputs(), i -> CollectionUtils.map(i.getMatchingStacksClient(), EntryStack::create));
+        this.input = EntryStack.create(recipe.getPreviewInputs());
         this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
         this.xp = recipe.getExperience();
         this.cookTime = recipe.getCookTime();

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

@@ -43,13 +43,7 @@ public class DefaultShapedDisplay implements DefaultCraftingDisplay {
     
     public DefaultShapedDisplay(ShapedRecipe recipe) {
         this.display = recipe;
-        this.input = recipe.getPreviewInputs().stream().map(i -> {
-            List<EntryStack> entries = new ArrayList<>();
-            for (ItemStack stack : i.getMatchingStacksClient()) {
-                entries.add(EntryStack.create(stack));
-            }
-            return entries;
-        }).collect(Collectors.toList());
+        this.input = EntryStack.create(recipe.getPreviewInputs());
         this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
     }
     

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

@@ -43,13 +43,7 @@ public class DefaultShapelessDisplay implements DefaultCraftingDisplay {
     
     public DefaultShapelessDisplay(ShapelessRecipe recipe) {
         this.display = recipe;
-        this.input = recipe.getPreviewInputs().stream().map(i -> {
-            List<EntryStack> entries = new ArrayList<>();
-            for (ItemStack stack : i.getMatchingStacksClient()) {
-                entries.add(EntryStack.create(stack));
-            }
-            return entries;
-        }).collect(Collectors.toList());
+        this.input = EntryStack.create(recipe.getPreviewInputs());
         this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
     }
     

+ 2 - 2
src/main/java/me/shedaniel/rei/plugin/smithing/DefaultSmithingDisplay.java

@@ -48,8 +48,8 @@ public class DefaultSmithingDisplay implements RecipeDisplay {
     public DefaultSmithingDisplay(@NotNull SmithingRecipe recipe) {
         this(
                 Lists.newArrayList(
-                        CollectionUtils.map(recipe.base.getMatchingStacksClient(), EntryStack::create),
-                        CollectionUtils.map(recipe.addition.getMatchingStacksClient(), EntryStack::create)
+                        EntryStack.create(recipe.base),
+                        EntryStack.create(recipe.addition)
                 ),
                 Collections.singletonList(EntryStack.create(recipe.getOutput())),
                 recipe.getId()

+ 1 - 7
src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingDisplay.java

@@ -51,13 +51,7 @@ public class DefaultStoneCuttingDisplay implements RecipeDisplay {
     }
     
     public DefaultStoneCuttingDisplay(DefaultedList<Ingredient> ingredients, ItemStack output) {
-        this.inputs = ingredients.stream().map(i -> {
-            List<EntryStack> entries = new ArrayList<>();
-            for (ItemStack stack : i.getMatchingStacksClient()) {
-                entries.add(EntryStack.create(stack));
-            }
-            return entries;
-        }).collect(Collectors.toList());
+        this.inputs = EntryStack.create(ingredients);
         this.output = Collections.singletonList(EntryStack.create(output));
     }