From 3ee2e33630d3346d9ab04c9e4c56f101f18399d2 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Tue, 23 Apr 2019 04:46:25 +0200 Subject: improved threaded loader +fixes not enabled ASM code Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: c7b407a7fed7730839a2613a93b5a985e7ae3a0e --- .../java/com/github/bartimaeusnek/ASM/BWCore.java | 15 +++++-- .../com/github/bartimaeusnek/ASM/BWCorePlugin.java | 22 ++++++--- .../bartimaeusnek/ASM/BWCoreTransformer.java | 39 +++++++++------- .../github/bartimaeusnek/bartworks/MainMod.java | 4 ++ .../ClientEventHandler/ClientEventHandler.java | 2 +- .../bartworks/common/configs/ConfigHandler.java | 6 ++- .../system/material/BW_MetaGenerated_Items.java | 8 +++- .../bartworks/system/material/OreDictHandler.java | 52 ---------------------- .../bartworks/system/material/ThreadedLoader.java | 6 ++- .../bartworks/system/material/WerkstoffLoader.java | 27 ++++++++--- .../bartworks/system/oredict/OreDictAdder.java | 51 +++++++++++++++++++++ .../bartworks/system/oredict/OreDictHandler.java | 52 ++++++++++++++++++++++ 12 files changed, 193 insertions(+), 91 deletions(-) delete mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/system/material/OreDictHandler.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictAdder.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java (limited to 'src/main') diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java index 9c76b3dd82..031ff30512 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java @@ -22,11 +22,13 @@ package com.github.bartimaeusnek.ASM; +import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; import cpw.mods.fml.common.DummyModContainer; import cpw.mods.fml.common.LoadController; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.versioning.ArtifactVersion; @@ -37,23 +39,28 @@ import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; +import static com.github.bartimaeusnek.ASM.BWCoreTransformer.shouldTransform; + public class BWCore extends DummyModContainer { public static final String BWCORE_NAME = "BartWorks ASM Core"; - public static final Logger BWCORE_LOG = LogManager.getLogger(BWCORE_NAME); + public static final Logger BWCORE_LOG = LogManager.getLogger(BWCore.BWCORE_NAME); public BWCore() { super(new ModMetadata()); - ModMetadata metadata = getMetadata(); + ModMetadata metadata = this.getMetadata(); metadata.modId = "BWCore"; - metadata.name = BWCORE_NAME; + metadata.name = BWCore.BWCORE_NAME; metadata.version = "0.0.1"; metadata.authorList.add("bartimaeusnek"); - metadata.dependants = getDependants(); + metadata.dependants = this.getDependants(); } @Subscribe public void preInit(FMLPreInitializationEvent event) { + shouldTransform[0] = Loader.isModLoaded("ExtraUtilities") && ConfigHandler.enabledPatches[0]; + shouldTransform[1] = Loader.isModLoaded("ExtraUtilities") && ConfigHandler.enabledPatches[1]; + BWCore.BWCORE_LOG.info("Extra Utilities found? " + shouldTransform[0]); } @Override diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java index 64206d5e56..97f4702d4c 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java @@ -28,27 +28,27 @@ import cpw.mods.fml.relauncher.IFMLLoadingPlugin; import net.minecraftforge.common.config.Configuration; import java.io.File; +import java.util.ArrayList; import java.util.Map; @IFMLLoadingPlugin.SortingIndex(999999999)//Load as late as possible (after fastcraft/OptiFine). @IFMLLoadingPlugin.MCVersion("1.7.10") -@IFMLLoadingPlugin.TransformerExclusions({"com.github.bartimaeusnek.ASM"}) +@IFMLLoadingPlugin.TransformerExclusions("com.github.bartimaeusnek.ASM") @IFMLLoadingPlugin.Name(BWCorePlugin.BWCORE_PLUGIN_NAME) public class BWCorePlugin implements IFMLLoadingPlugin { public static final String BWCORE_PLUGIN_NAME = "BartWorks ASM Core Plugin"; - public static File minecraftDir = null; + public static File minecraftDir; public BWCorePlugin() { //Injection Code taken from CodeChickenLib - if (minecraftDir != null) + if (BWCorePlugin.minecraftDir != null) return;//get called twice, once for IFMLCallHook - minecraftDir = (File) FMLInjectionData.data()[6]; + BWCorePlugin.minecraftDir = (File) FMLInjectionData.data()[6]; //do all the configuration already now... - new ConfigHandler(new Configuration(new File(new File(minecraftDir, "config"), "bartworks.cfg"))); - //config Override if mods are missing. - new BWCoreTransformer().checkForMods(); + new ConfigHandler(new Configuration(new File(new File(BWCorePlugin.minecraftDir, "config"), "bartworks.cfg"))); + BWCoreTransformer.shouldTransform[2] = false; } @Override @@ -71,6 +71,14 @@ public class BWCorePlugin implements IFMLLoadingPlugin { if (data.get("runtimeDeobfuscationEnabled") != null) { BWCoreTransformer.obfs = (boolean) data.get("runtimeDeobfuscationEnabled"); } + if (data.get("coremodList") != null) { + for (Object o : (ArrayList) data.get("coremodList")) { + if (o.toString().contains("MicdoodlePlugin")) { + BWCoreTransformer.shouldTransform[2] = ConfigHandler.enabledPatches[2]; + break; + } + } + } } @Override diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java index 41c1164db4..bcc67b18d3 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java @@ -23,12 +23,15 @@ package com.github.bartimaeusnek.ASM; import net.minecraft.launchwrapper.IClassTransformer; +import net.minecraft.launchwrapper.Launch; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.*; +import java.io.File; import java.util.Arrays; import java.util.List; +import java.util.jar.JarFile; import static org.objectweb.asm.Opcodes.*; @@ -47,23 +50,25 @@ public class BWCoreTransformer implements IClassTransformer { public static boolean[] shouldTransform = new boolean[CLASSESBEEINGTRANSFORMED.length]; - public void checkForMods() { - //hacky way to detect if the mods are loaded - try{ - Class.forName("com.rwtema.extrautils.core.Tuple"); - shouldTransform[0] = true; - shouldTransform[1] = true; - }catch (ClassNotFoundException e){ - shouldTransform[0] = false; - shouldTransform[1] = false; - } - try{ - Class.forName("micdoodle8.mods.galacticraft.core.Constants"); - shouldTransform[2] = true; - }catch (ClassNotFoundException e){ - shouldTransform[2] = false; - } - } +// public void checkForMods() { +// //hacky way to detect if the mods are loaded +// try{ +// Class.forName("com.rwtema.extrautils.core.Tuple"); +// shouldTransform[0] = true; +// shouldTransform[1] = true; +// }catch (ClassNotFoundException e){ +// BWCore.BWCORE_LOG.info("Extra Utilities not found!"); +// shouldTransform[0] = false; +// shouldTransform[1] = false; +// } +// try{ +// Class.forName("micdoodle8.mods.galacticraft.core.Constants"); +// shouldTransform[2] = true; +// }catch (ClassNotFoundException e){ +// BWCore.BWCORE_LOG.info("micdoodle Core not found!"); +// shouldTransform[2] = false; +// } +// } public static byte[] transform(int id, byte[] basicClass) { if (!BWCoreTransformer.shouldTransform[id]) { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java index 522943fba4..e5ee488b2f 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java @@ -49,6 +49,8 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartedEvent; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.registry.GameData; +import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.SubTag; @@ -57,6 +59,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.init.Blocks; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; @@ -64,6 +67,7 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; import java.util.HashSet; +import java.util.Iterator; import static com.github.bartimaeusnek.bartworks.common.tileentities.multis.GT_TileEntity_ElectricImplosionCompressor.eicMap; diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java index 5888b88ef2..d2277817c5 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java @@ -25,7 +25,7 @@ package com.github.bartimaeusnek.bartworks.client.ClientEventHandler; import com.github.bartimaeusnek.bartworks.API.BioVatLogicAdder; import com.github.bartimaeusnek.bartworks.MainMod; import com.github.bartimaeusnek.bartworks.common.blocks.BW_Blocks; -import com.github.bartimaeusnek.bartworks.system.material.OreDictHandler; +import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler; import com.github.bartimaeusnek.bartworks.util.BW_ColorUtil; import com.github.bartimaeusnek.bartworks.util.ChatColorHelper; import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java index cce52a223d..669417a345 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java @@ -26,6 +26,8 @@ package com.github.bartimaeusnek.bartworks.common.configs; import com.github.bartimaeusnek.ASM.BWCoreTransformer;; import net.minecraftforge.common.config.Configuration; +import java.util.Arrays; + public class ConfigHandler { private static final int IDU = 10 * 8 + 5; public static int IDOffset = 12600; @@ -44,7 +46,7 @@ public class ConfigHandler { public static boolean experimentalThreadedLoader; public static boolean GTNH; public static boolean ezmode; - + public static boolean[] enabledPatches ; public ConfigHandler(Configuration C) { ConfigHandler.c = C; @@ -67,6 +69,8 @@ public class ConfigHandler { for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++) { BWCoreTransformer.shouldTransform[i] = ConfigHandler.c.get("ASM fixes", BWCoreTransformer.DESCRIPTIONFORCONFIG[i] + " in class: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i], true).getBoolean(true); } + enabledPatches = new boolean[BWCoreTransformer.shouldTransform.length]; + enabledPatches = Arrays.copyOf(BWCoreTransformer.shouldTransform,BWCoreTransformer.shouldTransform.length); ConfigHandler.ross128BID = ConfigHandler.c.get("CrossMod Interactions", "DimID - Ross128b", -64, "The Dim ID for Ross128b").getInt(-64); ConfigHandler.ross128BAID = ConfigHandler.c.get("CrossMod Interactions", "DimID - Ross128ba", -63, "The Dim ID for Ross128ba (Ross128b's Moon)").getInt(-63); diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/BW_MetaGenerated_Items.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/BW_MetaGenerated_Items.java index f77c8ea745..552548c4d6 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/BW_MetaGenerated_Items.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/BW_MetaGenerated_Items.java @@ -22,7 +22,10 @@ package com.github.bartimaeusnek.bartworks.system.material; +import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; +import com.github.bartimaeusnek.bartworks.system.oredict.OreDictAdder; import com.github.bartimaeusnek.bartworks.util.ChatColorHelper; +import com.github.bartimaeusnek.bartworks.util.Pair; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gregtech.api.enums.Materials; @@ -69,7 +72,10 @@ public class BW_MetaGenerated_Items extends GT_MetaGenerated_Item { continue; GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(tStack) + ".name", this.getDefaultLocalization(w)); GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(tStack) + ".tooltip", w.getToolTip()); - GT_OreDictUnificator.registerOre(this.orePrefixes.name() + w.getDefaultName().replaceAll(" ",""), tStack); + if (ConfigHandler.experimentalThreadedLoader) + OreDictAdder.addToMap(new Pair<>(this.orePrefixes.name() + w.getDefaultName().replaceAll(" ",""), tStack)); + else + GT_OreDictUnificator.registerOre(this.orePrefixes.name() + w.getDefaultName().replaceAll(" ",""), tStack); } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/OreDictHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/OreDictHandler.java deleted file mode 100644 index 0715d00a90..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/OreDictHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2019 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.system.material; - -import gregtech.api.enums.OrePrefixes; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; - -import java.util.HashMap; - -public class OreDictHandler { - - private static final HashMap cache = new HashMap<>(); - - public static HashMap getCache() { - return OreDictHandler.cache; - } - - public static ItemStack getItemStack(String elementName, OrePrefixes prefixes, int amount){ - if (cache.get(prefixes+elementName.replaceAll(" ","")) != null){ - ItemStack tmp = cache.get(prefixes+elementName.replaceAll(" ","")).copy(); - tmp.stackSize=amount; - return tmp; - } else if (!OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).isEmpty()){ - ItemStack tmp = OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).get(0).copy(); - tmp.stackSize=amount; - cache.put(prefixes+elementName.replaceAll(" ",""),tmp); - return tmp; - } - return null; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/ThreadedLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/ThreadedLoader.java index d34fd03818..bb3bea4915 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/ThreadedLoader.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/ThreadedLoader.java @@ -23,6 +23,7 @@ package com.github.bartimaeusnek.bartworks.system.material; import com.github.bartimaeusnek.bartworks.MainMod; +import com.github.bartimaeusnek.bartworks.system.oredict.OreDictAdder; import cpw.mods.fml.common.FMLCommonHandler; import java.util.ArrayList; @@ -40,6 +41,7 @@ public class ThreadedLoader implements Runnable { MainMod.LOGGER.info("Starting to register BartWorks Materials Recipes to Gregtech"); threads.add(new AllRecipes()); threads.forEach(Thread::start); + } public synchronized void runInit() { @@ -57,9 +59,11 @@ public class ThreadedLoader implements Runnable { } } MainMod.LOGGER.info("Successfully joined the Material Generation Thread, Registering the Items/Blocks to the GameRegistry"); + if ((WerkstoffLoader.toGenerateGlobal) != 0){ + OreDictAdder.addToOreDict(); + } if ((WerkstoffLoader.toGenerateGlobal & 0b1000) != 0) WerkstoffLoader.INSTANCE.gameRegistryHandler(); - } class AllRecipes extends Thread { 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 7256b12a43..e5848f2789 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 @@ -28,6 +28,8 @@ import com.github.bartimaeusnek.bartworks.client.renderer.BW_Renderer_Block_Ores import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.bartworks.system.log.DebugLog; import com.github.bartimaeusnek.bartworks.system.material.processingLoaders.AdditionalRecipes; +import com.github.bartimaeusnek.bartworks.system.oredict.OreDictAdder; +import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler; import com.github.bartimaeusnek.bartworks.util.BW_ColorUtil; import com.github.bartimaeusnek.bartworks.util.Pair; import com.github.bartimaeusnek.crossmod.thaumcraft.util.ThaumcraftHandler; @@ -607,14 +609,25 @@ public class WerkstoffLoader implements Runnable { } private void runAdditionalOreDict(){ - for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) { - if (werkstoff.getGenerationFeatures().hasOres()) - GT_OreDictUnificator.registerOre(ore + werkstoff.getDefaultName().replaceAll(" ",""), werkstoff.get(ore)); - if (werkstoff.getGenerationFeatures().hasGems()) - OreDictionary.registerOre("craftingLens" + BW_ColorUtil.getDyeFromColor(werkstoff.getRGBA()).mName.replace(" ", ""), werkstoff.get(lens)); - } + if (ConfigHandler.experimentalThreadedLoader){ + for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) { + if (werkstoff.getGenerationFeatures().hasOres()) + OreDictAdder.addToMap(new Pair<>(ore + werkstoff.getDefaultName().replaceAll(" ", ""), werkstoff.get(ore))); + if (werkstoff.getGenerationFeatures().hasGems()) + OreDictAdder.addToMap(new Pair<>("craftingLens" + BW_ColorUtil.getDyeFromColor(werkstoff.getRGBA()).mName.replace(" ", ""), werkstoff.get(lens))); + } - GT_OreDictUnificator.registerOre("craftingIndustrialDiamond", WerkstoffLoader.Zirconia.get(gemExquisite)); + OreDictAdder.addToMap(new Pair<>("craftingIndustrialDiamond", WerkstoffLoader.Zirconia.get(gemExquisite))); + }else { + for (Werkstoff werkstoff : Werkstoff.werkstoffHashSet) { + if (werkstoff.getGenerationFeatures().hasOres()) + GT_OreDictUnificator.registerOre(ore + werkstoff.getDefaultName().replaceAll(" ", ""), werkstoff.get(ore)); + if (werkstoff.getGenerationFeatures().hasGems()) + OreDictionary.registerOre("craftingLens" + BW_ColorUtil.getDyeFromColor(werkstoff.getRGBA()).mName.replace(" ", ""), werkstoff.get(lens)); + } + + GT_OreDictUnificator.registerOre("craftingIndustrialDiamond", WerkstoffLoader.Zirconia.get(gemExquisite)); + } } private void addGemRecipes(Werkstoff werkstoff) { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictAdder.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictAdder.java new file mode 100644 index 0000000000..25e3598df0 --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictAdder.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 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.system.oredict; + +import com.github.bartimaeusnek.bartworks.util.Pair; +import gregtech.api.util.GT_OreDictUnificator; +import net.minecraft.item.ItemStack; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class OreDictAdder { + + private static ConcurrentHashMap toAddMap = new ConcurrentHashMap<>(); + + public static synchronized void addToMap(Pair element){ + OreDictAdder.toAddMap.put(element.getKey(),element.getValue()); + } + + public static synchronized void addToMap(Pair... elements){ + for (Pair p : elements) + OreDictAdder.toAddMap.put(p.getKey(),p.getValue()); + } + + public static void addToOreDict(){ + for (Map.Entry entry: toAddMap.entrySet()){ + GT_OreDictUnificator.registerOre(entry.getKey(),entry.getValue()); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java new file mode 100644 index 0000000000..e86d55acce --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 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.system.oredict; + +import gregtech.api.enums.OrePrefixes; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.HashMap; + +public class OreDictHandler { + + private static final HashMap cache = new HashMap<>(); + + public static HashMap getCache() { + return OreDictHandler.cache; + } + + public static ItemStack getItemStack(String elementName, OrePrefixes prefixes, int amount){ + if (cache.get(prefixes+elementName.replaceAll(" ","")) != null){ + ItemStack tmp = cache.get(prefixes+elementName.replaceAll(" ","")).copy(); + tmp.stackSize=amount; + return tmp; + } else if (!OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).isEmpty()){ + ItemStack tmp = OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).get(0).copy(); + tmp.stackSize=amount; + cache.put(prefixes+elementName.replaceAll(" ",""),tmp); + return tmp; + } + return null; + } +} -- cgit