diff --git a/build.properties b/build.properties index 5d372d679..fd4a76fe7 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 bartimaeusnek +# Copyright (c) 2018-2020 bartimaeusnek # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ mc_version=1.7.10 majorUpdate=0 minorUpdate=5 -buildNumber=10 +buildNumber=11 APIVersion=8 ic2.version=2.2.828-experimental gregtech.version=5.09.32.36 diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java index d9ff910ff..72a9477e5 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 bartimaeusnek + * Copyright (c) 2018-2020 bartimaeusnek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,6 +22,7 @@ package com.github.bartimaeusnek.ASM; +import com.github.bartimaeusnek.bartworks.util.NonNullWrappedHashSet; import com.github.bartimaeusnek.bartworks.util.accessprioritylist.AccessPriorityList; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; @@ -96,16 +97,28 @@ public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCraf } ItemStack stack = null; - HashSet recipeHashSet = new HashSet<>(); - for (IRecipe recipe : (List) CraftingManager.getInstance().getRecipeList()) - if (recipe.matches(inventoryCrafting, world)) - recipeHashSet.add(recipe); - - for (IRecipe recipe : recipeHashSet){ - stack = recipe.getCraftingResult(inventoryCrafting); - if (stack != null && recipeHashSet.size() == 1) - RECENTLYUSEDRECIPES.addLast(recipe); + + HashSet recipeSet = new NonNullWrappedHashSet<>(); + List recipeList = CraftingManager.getInstance().getRecipeList(); + + for (int k = 0; k < recipeList.size(); k++) { + recipeSet.add((IRecipe) recipeList.get(k)); } + + Object[] arr = recipeSet.parallelStream().filter(r -> r.matches(inventoryCrafting, world)).toArray(); + + if (arr.length == 0) + return null; + + IRecipe recipe = (IRecipe) arr[0]; + stack = recipe.getCraftingResult(inventoryCrafting); + + if (arr.length != 1) + return stack; + + if (stack != null) + RECENTLYUSEDRECIPES.addLast(recipe); + return stack; } } @@ -113,4 +126,4 @@ public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCraf private BWCoreStaticReplacementMethodes() { } -} +} \ No newline at end of file diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java index 0bc0a806a..9d83e88b5 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 bartimaeusnek + * Copyright (c) 2018-2020 bartimaeusnek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,6 +53,7 @@ import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler; import com.github.bartimaeusnek.bartworks.util.BWRecipes; import com.github.bartimaeusnek.bartworks.util.BW_Util; +import com.github.bartimaeusnek.bartworks.util.StreamUtils; import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; import com.google.common.collect.ArrayListMultimap; import cpw.mods.fml.common.FMLCommonHandler; @@ -230,7 +231,6 @@ public void onModLoadingComplete(FMLLoadCompleteEvent event) { PlatinumSludgeOverHaul.replacePureElements(); runOnServerStarted(); - fixEnergyRequirements(); MainMod.unificationRecipeEnforcer(); } @@ -248,25 +248,27 @@ public static void runOnPlayerJoined(boolean classicMode, boolean extraGasRecipe } if (classicMode) new DownTierLoader().run(); -// removeDuplicateRecipes(); +// removeDuplicateRecipes(); recipesAdded = true; } + fixEnergyRequirements(); + + //Accept recipe map changes into Buffers + GT_Recipe.GT_Recipe_Map.sMappings.forEach(GT_Recipe.GT_Recipe_Map::reInit); } private static void fixEnergyRequirements() { - maploop: - for (GT_Recipe.GT_Recipe_Map map : GT_Recipe.GT_Recipe_Map.sMappings) { - for (GT_Recipe recipe : map.mRecipeList) { - if (recipe.mFakeRecipe) - continue maploop; - for (int i = 0; i < (VN.length - 1); i++) { - if (recipe.mEUt == BW_Util.getTierVoltage(i)) { - recipe.mEUt = BW_Util.getMachineVoltageFromTier(i); + GT_Recipe.GT_Recipe_Map.sMappings.stream() + .filter(StreamUtils::filterVisualMaps) + .forEach(gt_recipe_map -> + gt_recipe_map.mRecipeList.parallelStream().forEach( gt_recipe -> { + for (int i = 0; i < (VN.length - 1); i++) { + if (gt_recipe.mEUt > BW_Util.getMachineVoltageFromTier(i) && gt_recipe.mEUt <= BW_Util.getTierVoltage(i)) { + gt_recipe.mEUt = BW_Util.getMachineVoltageFromTier(i); + } } - } - } - } + })); } private static void unificationRecipeEnforcer() { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/RecipeLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/RecipeLoader.java index 3f703ba68..34401b4d1 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/RecipeLoader.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/loaders/RecipeLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 bartimaeusnek + * Copyright (c) 2018-2020 bartimaeusnek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -103,7 +103,7 @@ public void run() { "CDC", "SBS", "CFC", - 'C', GT_OreDictUnificator.get(OrePrefixes.circuit, ConfigHandler.GTNH ? Materials.Advanced : Materials.Basic, 1L), + 'C', ConfigHandler.GTNH ? "circuitAdvanced" : "circuitBasic", 'D', ItemList.Cover_Screen.get(1L), 'S', GT_OreDictUnificator.get(OrePrefixes.cableGt12, ConfigHandler.GTNH ? Materials.Platinum : Materials.AnnealedCopper, 1L), 'B', new ItemStack(ItemRegistry.BW_BLOCKS[1]), @@ -112,24 +112,24 @@ public void run() { GT_ModHandler.addCraftingRecipe( new ItemStack(ItemRegistry.DESTRUCTOPACK), - RecipeLoader.BITSD, + GT_ModHandler.RecipeBits.NOT_REMOVABLE, new Object[]{ "CPC", "PLP", "CPC", - 'C', GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 1L), + 'C', "circuitAdvanced", 'P', GT_OreDictUnificator.get(ConfigHandler.GTNH ? OrePrefixes.plateDouble : OrePrefixes.plate, Materials.Aluminium, 1L), 'L', new ItemStack(Items.lava_bucket) }); GT_ModHandler.addCraftingRecipe( new ItemStack(ItemRegistry.DESTRUCTOPACK), - RecipeLoader.BITSD, + GT_ModHandler.RecipeBits.NOT_REMOVABLE, new Object[]{ "CPC", "PLP", "CPC", - 'C', GT_OreDictUnificator.get(OrePrefixes.circuit, Materials.Advanced, 1L), + 'C', "circuitAdvanced", 'P', GT_OreDictUnificator.get(ConfigHandler.GTNH ? OrePrefixes.plateDouble : OrePrefixes.plate, ConfigHandler.GTNH ? Materials.Steel : Materials.Iron, 1L), 'L', new ItemStack(Items.lava_bucket) }); diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/WerkstoffLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/WerkstoffLoader.java index ec43fce23..3b1079cb8 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/WerkstoffLoader.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/WerkstoffLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 bartimaeusnek + * Copyright (c) 2018-2020 bartimaeusnek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -764,6 +764,7 @@ private WerkstoffLoader() {} public static final Werkstoff PTResidue = new Werkstoff( new short[]{0x64,0x63,0x2E}, "Platinum Residue", + "??IrOsRhRu??", new Werkstoff.Stats(), Werkstoff.Types.MIXTURE, new Werkstoff.GenerationFeatures().disable().onlyDust(), @@ -899,7 +900,7 @@ private WerkstoffLoader() {} public static final Werkstoff LeachResidue = new Werkstoff( new short[]{0x64, 0x46, 0x29}, "Leach Residue", - "??IrOsRhRu??", + "??IrOsRu??", new Werkstoff.Stats(), Werkstoff.Types.MIXTURE, new Werkstoff.GenerationFeatures(), @@ -1731,8 +1732,8 @@ private static void runGTItemDataRegistrator() { } public static void addAssociationToItems() { - Arrays.stream(values()).forEach( prefixes -> { - Werkstoff.werkstoffHashSet.stream() + Arrays.stream(values()).forEach( prefixes -> + Werkstoff.werkstoffHashSet.stream() .filter(werkstoff -> werkstoff.hasItemType(prefixes) && (werkstoff.getGenerationFeatures().blacklist & Werkstoff.GenerationFeatures.prefixLogic.get(prefixes)) == 0) .forEach(werkstoff -> { Materials werkstoffBridgeMaterial = werkstoff.getBridgeMaterial(); @@ -1741,8 +1742,7 @@ public static void addAssociationToItems() { GT_OreDictUnificator.addAssociation(prefixes, werkstoffBridgeMaterial, stack, false); GT_OreDictUnificator.set(prefixes, werkstoffBridgeMaterial, stack, true, true); } - }); - }); + })); } /** diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/processingLoaders/DownTierLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/processingLoaders/DownTierLoader.java index ff080eab8..320bf534f 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/processingLoaders/DownTierLoader.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/processingLoaders/DownTierLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 bartimaeusnek + * Copyright (c) 2018-2020 bartimaeusnek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,6 +23,7 @@ package com.github.bartimaeusnek.bartworks.system.material.processingLoaders; import com.github.bartimaeusnek.bartworks.util.BW_Util; +import com.github.bartimaeusnek.bartworks.util.StreamUtils; import gregtech.api.util.GT_Recipe; import java.util.HashSet; @@ -33,13 +34,8 @@ public class DownTierLoader implements Runnable { @Override public void run() { - GT_Recipe.GT_Recipe_Map.sMappings.stream().filter(map -> - !(map == GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes - || map == GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes - || map == GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes - || map == GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes - || map == GT_Recipe.GT_Recipe_Map.sFusionRecipes - || map == GT_Recipe.GT_Recipe_Map.sRockBreakerFakeRecipes)) + GT_Recipe.GT_Recipe_Map.sMappings.stream() + .filter(map -> StreamUtils.filterVisualMaps(map) && map != GT_Recipe.GT_Recipe_Map.sFusionRecipes) .forEach(map -> { Set newRecipes = new HashSet<>(); Set toRem = new HashSet<>(); diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/NonNullWrappedHashSet.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/NonNullWrappedHashSet.java new file mode 100644 index 000000000..f7ed76278 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/NonNullWrappedHashSet.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.util; + +import java.util.Collection; +import java.util.HashSet; + +public class NonNullWrappedHashSet extends HashSet { + + public NonNullWrappedHashSet() { + super(); + } + + public NonNullWrappedHashSet(Collection c) { + super(); + this.addAll(c); + } + + public NonNullWrappedHashSet(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + public NonNullWrappedHashSet(int initialCapacity) { + super(initialCapacity); + } + + public boolean add(E e) { + if (e != null) + return super.add(e); + return false; + } + + public boolean addAll(Collection c) { + boolean wasChanged = false; + for (E element : c) { + if (element != null) + wasChanged |= this.add(element); + } + return wasChanged; + } +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/util/StreamUtils.java b/src/main/java/com/github/bartimaeusnek/bartworks/util/StreamUtils.java new file mode 100644 index 000000000..9083ee468 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/util/StreamUtils.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018-2020 bartimaeusnek + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.bartimaeusnek.bartworks.util; + +import gregtech.api.util.GT_Recipe; + +import java.util.Optional; +import java.util.function.Predicate; + +public class StreamUtils { + private StreamUtils(){} + + public static Predicate filterVisualMaps() { + return gt_recipe_map -> { + Optional op = gt_recipe_map.mRecipeList.stream().findAny(); + return op.isPresent() && !op.get().mFakeRecipe; + }; + } + + public static boolean filterVisualMaps(GT_Recipe.GT_Recipe_Map gt_recipe_map) { + return filterVisualMaps().test(gt_recipe_map); + } +}