diff options
author | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2020-03-07 00:28:33 +0100 |
---|---|---|
committer | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2020-03-07 00:28:33 +0100 |
commit | d5c408cfb2a4d2ede082544f60235e71d01a52b7 (patch) | |
tree | 028c36e179444ceca0af18609ec5a469f6e67870 /src/main/java | |
parent | 074dd1f7ad09cb47d2612f641ec30716b3cd15cb (diff) | |
download | GT5-Unofficial-d5c408cfb2a4d2ede082544f60235e71d01a52b7.tar.gz GT5-Unofficial-d5c408cfb2a4d2ede082544f60235e71d01a52b7.tar.bz2 GT5-Unofficial-d5c408cfb2a4d2ede082544f60235e71d01a52b7.zip |
Fixes #50 #51 #52
+ fixes a bug where old recipes were still chosen due to missing buffer update
+ copyright update
+ version increase
Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>
Former-commit-id: 0e7d755c5043c8f4d1e402e3ce63d9bf9b34bb8d
Diffstat (limited to 'src/main/java')
7 files changed, 160 insertions, 45 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java index d9ff910ff8..72a9477e59 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 class BWCoreStaticReplacementMethodes { } ItemStack stack = null; - HashSet<IRecipe> recipeHashSet = new HashSet<>(); - for (IRecipe recipe : (List<IRecipe>) 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<IRecipe> 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 class BWCoreStaticReplacementMethodes { 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 0bc0a806a4..9d83e88b57 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.material.processingLoaders.Down 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 final class MainMod { PlatinumSludgeOverHaul.replacePureElements(); runOnServerStarted(); - fixEnergyRequirements(); MainMod.unificationRecipeEnforcer(); } @@ -248,25 +248,27 @@ public final class MainMod { } 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 3f703ba688..34401b4d11 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 class RecipeLoader implements Runnable { "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 class RecipeLoader implements Runnable { 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 ec43fce23c..3b1079cb83 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 @@ public class WerkstoffLoader implements Runnable { 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 @@ public class WerkstoffLoader implements Runnable { 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 @@ public class WerkstoffLoader implements Runnable { } 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 class WerkstoffLoader implements Runnable { 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 ff080eab82..320bf534fb 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<GT_Recipe> newRecipes = new HashSet<>(); Set<GT_Recipe> 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 0000000000..f7ed76278e --- /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<E> extends HashSet<E> { + + public NonNullWrappedHashSet() { + super(); + } + + public NonNullWrappedHashSet(Collection<? extends E> 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<? extends E> 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 0000000000..9083ee468f --- /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<GT_Recipe.GT_Recipe_Map> filterVisualMaps() { + return gt_recipe_map -> { + Optional<GT_Recipe> 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); + } +} |