diff options
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_ModHandler.java | 93 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GT_RecipeRegistrator.java | 103 |
2 files changed, 145 insertions, 51 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..01279b01a4 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.*; @@ -1014,7 +1015,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 +1393,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 +1432,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 +1442,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 +1585,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); diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java index 0358dfec4b..d10f6da434 100644 --- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java @@ -16,7 +16,8 @@ import java.util.Arrays; import java.util.List; import static gregtech.api.enums.GT_Values.*; - +import static gregtech.api.enums.Materials.Void; +import static gregtech.api.enums.Materials.*; /** * Class for Automatic Recipe registering. */ @@ -275,39 +276,77 @@ public class GT_RecipeRegistrator { } /** - * You give this Function a Material and it will scan almost everything for adding recycling Recipes + * Place Materials which you want to replace in Non-GT-Recipes here (warning HUGHE impact on loading times!) + */ + private final static Materials[] VANILLA_MATS = { + Cobalt, + Gold, + Iron, + Lead, + FierySteel, + Void, + Bronze, + Diamond, + Ruby, + Sapphire, + Steel, + IronWood, + Steeleaf, + Knightmetal, + Thaumium, + DarkSteel, + }; + + /** + * You give this Function a Material and it will scan almost everything for adding recycling Recipes and replacing Ingots, Gems etc. * - * @param aMat a Material, for example an Ingot or a Gem. - * @param aOutput the Dust you usually get from macerating aMat + * @param aMats Materials, for example an Ingot or a Gem. + * @param aPlate the Plate referenced to aMat * @param aRecipeReplacing allows to replace the Recipe with a Plate variant */ - public static synchronized void registerUsagesForMaterials(ItemStack aMat, String aPlate, boolean aRecipeReplacing) { - if (aMat == null) return; - aMat = GT_Utility.copy(aMat); - ItemStack tStack; - ItemData aItemData = GT_OreDictUnificator.getItemData(aMat); - if (aItemData == null || aItemData.mPrefix != OrePrefixes.ingot) aPlate = null; - if (aPlate != null && GT_OreDictUnificator.getFirstOre(aPlate, 1) == null) aPlate = null; - - sMt1.func_150996_a(aMat.getItem()); - sMt1.stackSize = 1; - Items.feather.setDamage(sMt1, Items.feather.getDamage(aMat)); - - sMt2.func_150996_a(new ItemStack(Blocks.dirt).getItem()); - sMt2.stackSize = 1; - Items.feather.setDamage(sMt2, 0); - - for (ItemStack[] tRecipe : sShapes1) { - int tAmount1 = 0; - for (ItemStack tMat : tRecipe) { - if (tMat == sMt1) tAmount1++; - } - if (aItemData != null && aItemData.hasValidPrefixMaterialData()) - for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputs(tRecipe)) { - GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1)); + public static synchronized void registerUsagesForMaterials(String aPlate, boolean aRecipeReplacing, ItemStack... aMats) { + for (ItemStack aMat : aMats) { + if (aMat == null) + continue; + + aMat = GT_Utility.copy(aMat); + + if (aMat == null) + continue; + + ItemData aItemData = GT_OreDictUnificator.getItemData(aMat); + if (aItemData == null || aItemData.mPrefix != OrePrefixes.ingot) aPlate = null; + if (aPlate != null && GT_OreDictUnificator.getFirstOre(aPlate, 1) == null) aPlate = null; + + sMt1.func_150996_a(aMat.getItem()); + sMt1.stackSize = 1; + Items.feather.setDamage(sMt1, Items.feather.getDamage(aMat)); + + sMt2.func_150996_a(new ItemStack(Blocks.dirt).getItem()); + sMt2.stackSize = 1; + Items.feather.setDamage(sMt2, 0); + + for (ItemStack[] tRecipe : sShapes1) { + int tAmount1 = 0; + for (ItemStack tMat : tRecipe) { + if (tMat == sMt1) tAmount1++; } + if (aItemData != null && aItemData.hasValidPrefixMaterialData()) + for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe)) { + GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1)); +// GT_Log.out.println("###################################################################################"); +// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate); +// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName()); +// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName()); +// GT_Log.out.println("###################################################################################"); + } + } + registerStickStuff(aPlate, aItemData, aRecipeReplacing); } + } + private static synchronized void registerStickStuff(String aPlate, ItemData aItemData, boolean aRecipeReplacing) { + ItemStack tStack; for (Materials tMaterial : sRodMaterialList) { ItemStack tMt2 = GT_OreDictUnificator.get(OrePrefixes.stick, tMaterial, 1); if (tMt2 != null) { @@ -331,6 +370,9 @@ public class GT_RecipeRegistrator { assert aItemData != null; if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.recipereplacements, aItemData.mMaterial.mMaterial + "." + sShapesA[i][0], true)) { if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe))) { +// GT_Log.out.println("###################################################################################"); +// GT_Log.out.println("registerStickStuff used aPlate: "+aPlate); +// GT_Log.out.println("###################################################################################"); switch (sShapesA[i].length) { case 2: GT_ModHandler.addCraftingRecipe(tStack, GT_ModHandler.RecipeBits.BUFFERED, new Object[]{sShapesA[i][1], s_P.charAt(0), aPlate, s_R.charAt(0), OrePrefixes.stick.get(tMaterial), s_I.charAt(0), aItemData}); @@ -350,4 +392,9 @@ public class GT_RecipeRegistrator { } } } + + public static boolean hasVanillaRecipes(Materials materials) { + return Arrays.stream(VANILLA_MATS).anyMatch(mat -> mat == materials); + } + } |