diff options
Diffstat (limited to 'src/main/java/gregtech/api/util/GT_ModHandler.java')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_ModHandler.java | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 8a1519234c..e195bf9b02 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -40,6 +40,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe; import java.util.*; import java.util.Map.Entry; +import java.util.stream.Collectors; import static gregtech.api.enums.GT_Values.*; @@ -777,6 +778,7 @@ public class GT_ModHandler { if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) GT_Utility.removeSimpleIC2MachineRecipe(aInput, getOreWashingRecipeList(), null); if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.orewashing, aInput, true)) return false; RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getWater(1000L), 500, 16); + RA.addOreWasherRecipe(aInput, (ItemStack)aOutput[0], (ItemStack)aOutput[1], (ItemStack)aOutput[2], GT_ModHandler.getDistilledWater(200L), 300, 16); if (GT_Mod.gregtechproxy.mAddGTRecipesToIC2Machines) { NBTTagCompound tNBT = new NBTTagCompound(); tNBT.setInteger("amount", aWaterAmount); @@ -1014,7 +1016,7 @@ public class GT_ModHandler { Character chr = (Character) aRecipe[idx]; Object in = aRecipe[idx + 1]; if (in instanceof ItemStack) { - tItemStackMap.put(chr, GT_Utility.copy((ItemStack) in)); + tItemStackMap.put(chr, GT_Utility.copy(in)); tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in)); } else if (in instanceof ItemData) { String tString = in.toString(); @@ -1392,7 +1394,7 @@ public class GT_ModHandler { * If you have multiple Mods, which add Bronze Armor for example * This also removes old Recipes from the List. */ - public static ArrayList<ItemStack> getVanillyToolRecipeOutputs(ItemStack... aRecipe) { + public static List<ItemStack> getVanillyToolRecipeOutputs(ItemStack... aRecipe) { if (!GregTech_API.sPostloadStarted || GregTech_API.sPostloadFinished) sSingleNonBlockDamagableRecipeList.clear(); if (sSingleNonBlockDamagableRecipeList.isEmpty()) { @@ -1431,7 +1433,7 @@ public class GT_ModHandler { } GT_Log.out.println("GT_Mod: Created a List of Tool Recipes containing " + sSingleNonBlockDamagableRecipeList.size() + " Recipes for recycling." + (sSingleNonBlockDamagableRecipeList.size() > 1024 ? " Scanning all these Recipes is the reason for the startup Lag you receive right now." : E)); } - ArrayList<ItemStack> rList = getRecipeOutputs(sSingleNonBlockDamagableRecipeList, true, aRecipe); + List<ItemStack> rList = getRecipeOutputs(sSingleNonBlockDamagableRecipeList, true, aRecipe); if (!GregTech_API.sPostloadStarted || GregTech_API.sPostloadFinished) sSingleNonBlockDamagableRecipeList.clear(); return rList; @@ -1441,49 +1443,95 @@ public class GT_ModHandler { * Gives you a list of the Outputs from a Crafting Recipe * If you have multiple Mods, which add Bronze Armor for example */ - public static ArrayList<ItemStack> getRecipeOutputs(ItemStack... aRecipe) { + public static List<ItemStack> getRecipeOutputs(ItemStack... aRecipe) { return getRecipeOutputs(CraftingManager.getInstance().getRecipeList(), false, aRecipe); } + private static List<IRecipe> bufferedRecipes = null; + + /** + * Gives you a list of the Outputs from a Crafting Recipe + * If you have multiple Mods, which add Bronze Armor for example + * Buffers a List which only has armor-alike crafting in it + */ + public static List<ItemStack> getRecipeOutputsBuffered(ItemStack... aRecipe) { + + if (bufferedRecipes == null) + bufferedRecipes = (List<IRecipe>) CraftingManager.getInstance().getRecipeList().stream().filter( + tRecipe -> !(tRecipe instanceof ShapelessRecipes) && !(tRecipe instanceof ShapelessOreRecipe) && !(tRecipe instanceof IGT_CraftingRecipe) + ) + .filter(tRecipe -> + { + try { + ItemStack tOutput = ((IRecipe) tRecipe).getRecipeOutput(); + if (tOutput.stackSize == 1 && tOutput.getMaxDamage() > 0 && tOutput.getMaxStackSize() == 1) { + return true; + } + } catch (Exception ignored) { + } + return false; + }) + .collect(Collectors.toList()); + return getRecipeOutputs(bufferedRecipes, false, aRecipe); + } + /** * Gives you a list of the Outputs from a Crafting Recipe * If you have multiple Mods, which add Bronze Armor for example */ - public static ArrayList<ItemStack> getRecipeOutputs(List<IRecipe> aList, boolean aDeleteFromList, ItemStack... aRecipe) { - ArrayList<ItemStack> rList = new ArrayList<ItemStack>(); - if (aRecipe == null) return rList; - boolean temp = false; - for (byte i = 0; i < aRecipe.length; i++) { - if (aRecipe[i] != null) { - temp = true; - break; - } - } - if (!temp) return rList; + public static List<ItemStack> getRecipeOutputs(List<IRecipe> aList, boolean aDeleteFromList, ItemStack... aRecipe) { + List<ItemStack> rList = new ArrayList<>(); + if (aRecipe == null || Arrays.stream(aRecipe).noneMatch(Objects::nonNull)) + return rList; InventoryCrafting aCrafting = new InventoryCrafting(new Container() { @Override public boolean canInteractWith(EntityPlayer var1) { return false; } }, 3, 3); - for (int i = 0; i < 9 && i < aRecipe.length; i++) aCrafting.setInventorySlotContents(i, aRecipe[i]); - for (int i = 0; i < aList.size(); i++) { - temp = false; + for (int i = 0; i < 9 && i < aRecipe.length; i++) + aCrafting.setInventorySlotContents(i, aRecipe[i]); + if (!aDeleteFromList) { + HashSet<ItemStack> stacks = new HashSet<>(); + aList.stream().filter( + tRecipe -> { + if (tRecipe instanceof ShapelessRecipes || tRecipe instanceof ShapelessOreRecipe || tRecipe instanceof IGT_CraftingRecipe) + return false; + try { + return tRecipe.matches(aCrafting, DW); + } catch (Throwable e) { + e.printStackTrace(GT_Log.err); + return false; + } + } + ).forEach(tRecipe -> stacks.add(tRecipe.getCraftingResult(aCrafting))); + rList = stacks.stream().filter(tOutput -> tOutput.stackSize == 1 && tOutput.getMaxDamage() > 0 && tOutput.getMaxStackSize() == 1).collect(Collectors.toList()); + } else for (int i = 0; i < aList.size(); i++) { + boolean temp = false; + try { temp = aList.get(i).matches(aCrafting, DW); } catch (Throwable e) { e.printStackTrace(GT_Log.err); } if (temp) { - ItemStack tOutput = aList.get(i).getCraftingResult(aCrafting); + IRecipe tRecipe = aList.get(i); + ItemStack tOutput = tRecipe.getCraftingResult(aCrafting); + if (tOutput == null || tOutput.stackSize <= 0) { // Seriously, who would ever do that shit? if (!GregTech_API.sPostloadFinished) throw new GT_ItsNotMyFaultException("Seems another Mod added a Crafting Recipe with null Output. Tell the Developer of said Mod to fix that."); - } else { - rList.add(GT_Utility.copy(tOutput)); - if (aDeleteFromList) aList.remove(i--); + continue; } + if (tOutput.stackSize != 1) continue; + if (tOutput.getMaxDamage() <= 0) continue; + if (tOutput.getMaxStackSize() != 1) continue; + if (tRecipe instanceof ShapelessRecipes) continue; + if (tRecipe instanceof ShapelessOreRecipe) continue; + if (tRecipe instanceof IGT_CraftingRecipe) continue; + rList.add(GT_Utility.copy(tOutput)); + aList.remove(i--); } } return rList; @@ -1538,7 +1586,7 @@ public class GT_ModHandler { for (Entry<IRecipeInput, RecipeOutput> tEntry : aRecipeList.entrySet()) { if (tEntry.getKey().matches(aInput)) { if (tEntry.getKey().getAmount() <= aInput.stackSize) { - ItemStack[] tList = (ItemStack[]) tEntry.getValue().items.toArray(new ItemStack[tEntry.getValue().items.size()]); + ItemStack[] tList = tEntry.getValue().items.toArray(new ItemStack[tEntry.getValue().items.size()]); if (tList.length == 0) break; ItemStack[] rList = new ItemStack[aOutputSlots.length]; rRecipeMetaData.setTag("return", tEntry.getValue().metadata); |