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 | 1730 |
1 files changed, 1730 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java new file mode 100644 index 0000000000..b657c8ee3f --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -0,0 +1,1730 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.*; +import gregtech.api.GregTech_API; +import gregtech.api.enums.*; +import gregtech.api.interfaces.IDamagableItem; +import gregtech.api.interfaces.IItemContainer; +import gregtech.api.interfaces.internal.IGT_CraftingRecipe; +import gregtech.api.objects.GT_HashSet; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.ItemData; +import ic2.api.item.IBoxable; +import ic2.api.item.IC2Items; +import ic2.api.item.IElectricItem; +import ic2.api.reactor.IReactorComponent; +import ic2.api.recipe.IRecipeInput; +import ic2.api.recipe.RecipeInputItemStack; +import ic2.api.recipe.RecipeOutput; +import ic2.core.AdvRecipe; + +import java.util.*; +import java.util.Map.Entry; + +import net.minecraft.block.Block; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.*; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import cpw.mods.fml.common.event.FMLInterModComms; +import cpw.mods.fml.common.registry.GameRegistry; + +/** + * NEVER INCLUDE THIS FILE IN YOUR MOD!!! + * + * This is the Interface I use for interacting with other Mods. + * + * Due to the many imports, this File can cause compile Problems if not all the APIs are installed + */ +public class GT_ModHandler { + public static volatile int VERSION = 508; + + /** + * Returns if that Liquid is Water or Distilled Water + */ + public static boolean isWater(FluidStack aFluid) { + if (aFluid == null) return F; + return aFluid.isFluidEqual(getWater(1)) || aFluid.isFluidEqual(getDistilledWater(1)); + } + + /** + * Returns a Liquid Stack with given amount of Water. + */ + public static FluidStack getWater(long aAmount) { + return FluidRegistry.getFluidStack("water", (int)aAmount); + } + + /** + * Returns a Liquid Stack with given amount of distilled Water. + */ + public static FluidStack getDistilledWater(long aAmount) { + return FluidRegistry.getFluidStack("ic2distilledwater", (int)aAmount); + } + + /** + * Returns if that Liquid is Lava + */ + public static boolean isLava(FluidStack aFluid) { + if (aFluid == null) return F; + return aFluid.isFluidEqual(getLava(1)); + } + + /** + * Returns a Liquid Stack with given amount of Lava. + */ + public static FluidStack getLava(long aAmount) { + return FluidRegistry.getFluidStack("lava", (int)aAmount); + } + + /** + * Returns if that Liquid is Steam + */ + public static boolean isSteam(FluidStack aFluid) { + if (aFluid == null) return F; + return aFluid.isFluidEqual(getSteam(1)); + } + + /** + * Returns a Liquid Stack with given amount of Steam. + */ + public static FluidStack getSteam(long aAmount) { + return FluidRegistry.getFluidStack("steam", (int)aAmount); + } + + /** + * Returns if that Liquid is Milk + */ + public static boolean isMilk(FluidStack aFluid) { + if (aFluid == null) return F; + return aFluid.isFluidEqual(getMilk(1)); + } + + /** + * Returns a Liquid Stack with given amount of Milk. + */ + public static FluidStack getMilk(long aAmount) { + return FluidRegistry.getFluidStack("milk", (int)aAmount); + } + + public static ItemStack getEmptyFuelCan(long aAmount) { + return ItemList.IC2_Fuel_Can_Empty.get(aAmount); + } + + public static ItemStack getEmptyCell(long aAmount) { + return ItemList.Cell_Empty.get(aAmount); + } + + public static ItemStack getAirCell(long aAmount) { + return ItemList.Cell_Air.get(aAmount); + } + + public static ItemStack getWaterCell(long aAmount) { + return ItemList.Cell_Water.get(aAmount); + } + + public static ItemStack getLavaCell(long aAmount) { + return ItemList.Cell_Lava.get(aAmount); + } + + /** + * @param aValue the Value of this Stack, when burning inside a Furnace (200 = 1 Burn Process = 500 EU, max = 32767 (that is 81917.5 EU)), limited to Short because the vanilla Furnace otherwise can't handle it properly, stupid Mojang... + */ + public static ItemStack setFuelValue(ItemStack aStack, short aValue) { + aStack.setTagCompound(GT_Utility.getNBTContainingShort(aStack.getTagCompound(), "GT.ItemFuelValue", aValue)); + return aStack; + } + + /** + * @return the Value of this Stack, when burning inside a Furnace (200 = 1 Burn Process = 500 EU, max = 32767 (that is 81917.5 EU)), limited to Short because the vanilla Furnace otherwise can't handle it properly, stupid Mojang... + */ + public static short getFuelValue(ItemStack aStack) { + return (short)TileEntityFurnace.getItemBurnTime(aStack); + } + + /** + * @param aValue Fuel value in EU + */ + public static ItemStack getFuelCan(int aValue) { + if (aValue < 5) return ItemList.IC2_Fuel_Can_Empty.get(1); + ItemStack rFuelCanStack = ItemList.IC2_Fuel_Can_Filled.get(1); + if (rFuelCanStack == null) return null; + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setInteger("value", aValue/5); + rFuelCanStack.setTagCompound(tNBT); + return rFuelCanStack; + } + + /** + * @param aFuelCan the Item you want to check + * @return the exact Value in EU the Fuel Can is worth if its even a Fuel Can. + */ + public static int getFuelCanValue(ItemStack aFuelCan) { + if (GT_Utility.isStackInvalid(aFuelCan) || !ItemList.IC2_Fuel_Can_Filled.isStackEqual(aFuelCan, F, T)) return 0; + NBTTagCompound tNBT = aFuelCan.getTagCompound(); + return tNBT==null?0:tNBT.getInteger("value")*5; + } + + private static final Map<String, ItemStack> sIC2ItemMap = new HashMap<String, ItemStack>(); + + /** + * Gets an Item from IndustrialCraft, and returns a Replacement Item if not possible + */ + public static ItemStack getIC2Item(String aItem, long aAmount, ItemStack aReplacement) { + if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null; + //if (D1) GT_Log.out.println("Requested the Item '" + aItem + "' from the IC2-API"); + if (!sIC2ItemMap.containsKey(aItem)) try {ItemStack tStack = IC2Items.getItem(aItem); sIC2ItemMap.put(aItem, tStack); if (tStack == null && D1) GT_Log.err.println(aItem + " is not found in the IC2 Items!");} catch (Throwable e) {/*Do nothing*/} + return GT_Utility.copyAmount(aAmount, sIC2ItemMap.get(aItem), aReplacement); + } + + /** + * Gets an Item from IndustrialCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible + */ + public static ItemStack getIC2Item(String aItem, long aAmount, int aMeta, ItemStack aReplacement) { + ItemStack rStack = getIC2Item(aItem, aAmount, aReplacement); + if (rStack == null) return null; + Items.feather.setDamage(rStack, aMeta); + return rStack; + } + + /** + * Gets an Item from IndustrialCraft, but the Damage Value can be specified + */ + public static ItemStack getIC2Item(String aItem, long aAmount, int aMeta) { + return getIC2Item(aItem, aAmount, aMeta, null); + } + + /** + * Gets an Item from IndustrialCraft + */ + public static ItemStack getIC2Item(String aItem, long aAmount) { + return getIC2Item(aItem, aAmount, null); + } + + /** + * Gets an Item from RailCraft + */ + public static ItemStack getModItem(String aModID, String aItem, long aAmount) { + return getModItem(aModID, aItem, aAmount, null); + } + + /** + * Gets an Item from RailCraft, and returns a Replacement Item if not possible + */ + public static ItemStack getModItem(String aModID, String aItem, long aAmount, ItemStack aReplacement) { + if (GT_Utility.isStringInvalid(aItem) || !GregTech_API.sPreloadStarted) return null; + return GT_Utility.copyAmount(aAmount, GameRegistry.findItemStack(aModID, aItem, (int)aAmount), aReplacement); + } + + /** + * Gets an Item from RailCraft, but the Damage Value can be specified + */ + public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta) { + ItemStack rStack = getModItem(aModID, aItem, aAmount); + if (rStack == null) return null; + Items.feather.setDamage(rStack, aMeta); + return rStack; + } + + /** + * Gets an Item from RailCraft, but the Damage Value can be specified, and returns a Replacement Item with the same Damage if not possible + */ + public static ItemStack getModItem(String aModID, String aItem, long aAmount, int aMeta, ItemStack aReplacement) { + ItemStack rStack = getModItem(aModID, aItem, aAmount, aReplacement); + if (rStack == null) return null; + Items.feather.setDamage(rStack, aMeta); + return rStack; + } + + /** + * OUT OF ORDER + */ + public static boolean getModeKeyDown(EntityPlayer aPlayer) { + return F; + } + + /** + * OUT OF ORDER + */ + public static boolean getBoostKeyDown(EntityPlayer aPlayer) { + return F; + } + + /** + * OUT OF ORDER + */ + public static boolean getJumpKeyDown(EntityPlayer aPlayer) { + return F; + } + + /** + * Adds a Valuable Ore to the Miner + */ + public static boolean addValuableOre(Block aBlock, int aMeta, int aValue) { + if (aValue <= 0) return F; + try { + Class.forName("ic2.core.IC2").getMethod("addValuableOre", IRecipeInput.class, int.class).invoke(null, new RecipeInputItemStack(new ItemStack(aBlock, 1, aMeta)), aValue); + } catch (Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Adds a Scrapbox Drop. Fails at April first for the "suddenly Hoes"-Feature of IC2 + */ + public static boolean addScrapboxDrop(float aChance, ItemStack aOutput) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aOutput == null || aChance <= 0) return F; + aOutput.stackSize = 1; + if (GT_Config.troll && !GT_Utility.areStacksEqual(aOutput, new ItemStack(Items.wooden_hoe, 1, 0))) return F; + aChance = (float)GregTech_API.sRecipeFile.get(ConfigCategories.Machines.scrapboxdrops, aOutput, aChance); + if (aChance <= 0) return F; + try { + GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", T, T), "addDrop", T, F, T, GT_Utility.copy(aOutput), aChance); + GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", T, T), "addRecipe", T, T, F, GT_Utility.copy(aOutput), aChance); + } catch (Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Adds an Item to the Recycler Blacklist + */ + public static boolean addToRecyclerBlackList(ItemStack aRecycledStack) { + if (aRecycledStack == null) return F; + try { + ic2.api.recipe.Recipes.recyclerBlacklist.add(new RecipeInputItemStack(aRecycledStack)); + } catch (Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Just simple Furnace smelting. Unbelievable how Minecraft fails at making a simple ItemStack->ItemStack mapping... + */ + public static boolean addSmeltingRecipe(ItemStack aInput, ItemStack aOutput) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aInput == null || aOutput == null || GT_Utility.getContainerItem(aInput, F) != null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.smelting, aInput, T)) return F; + FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F); + return T; + } + + /** + * Adds to Furnace AND Alloysmelter AND Induction Smelter + */ + public static boolean addSmeltingAndAlloySmeltingRecipe(ItemStack aInput, ItemStack aOutput) { + if (aInput == null || aOutput == null) return F; + boolean temp = F; + if (aInput.stackSize == 1 && addSmeltingRecipe(aInput, aOutput)) temp = T; + if (RA.addAlloySmelterRecipe(aInput, OrePrefixes.ingot.contains(aOutput)?ItemList.Shape_Mold_Ingot.get(0):OrePrefixes.block.contains(aOutput)?ItemList.Shape_Mold_Block.get(0):OrePrefixes.nugget.contains(aOutput)?ItemList.Shape_Mold_Nugget.get(0):null, aOutput, 130, 3)) temp = T; + if (addInductionSmelterRecipe(aInput, null, aOutput, null, aOutput.stackSize*1600, 0)) temp = T; + return temp; + } + + /** + * LiquidTransposer Recipe for both directions + */ + public static boolean addLiquidTransposerRecipe(ItemStack aEmptyContainer, FluidStack aLiquid, ItemStack aFullContainer, int aMJ) { + aFullContainer = GT_OreDictUnificator.get(T, aFullContainer); + if (aEmptyContainer == null || aFullContainer == null || aLiquid == null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.liquidtransposer, aFullContainer, T)) return F; + try { + ThermalExpansion.addTransposerFill(aMJ*10, aEmptyContainer, aFullContainer, aLiquid, T); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * LiquidTransposer Recipe for filling Containers + */ + public static boolean addLiquidTransposerFillRecipe(ItemStack aEmptyContainer, FluidStack aLiquid, ItemStack aFullContainer, int aMJ) { + aFullContainer = GT_OreDictUnificator.get(T, aFullContainer); + if (aEmptyContainer == null || aFullContainer == null || aLiquid == null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.liquidtransposerfilling, aFullContainer, T)) return F; + try { + ThermalExpansion.addTransposerFill(aMJ*10, aEmptyContainer, aFullContainer, aLiquid, F); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * LiquidTransposer Recipe for emptying Containers + */ + public static boolean addLiquidTransposerEmptyRecipe(ItemStack aFullContainer, FluidStack aLiquid, ItemStack aEmptyContainer, int aMJ) { + aEmptyContainer = GT_OreDictUnificator.get(T, aEmptyContainer); + if (aFullContainer == null || aEmptyContainer == null || aLiquid == null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.liquidtransposeremptying, aFullContainer, T)) return F; + try { + ThermalExpansion.addTransposerExtract(aMJ*10, aFullContainer, aEmptyContainer, aLiquid, 100, F); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * IC2-Extractor Recipe. Overloads old Recipes automatically + */ + public static boolean addExtractionRecipe(ItemStack aInput, ItemStack aOutput) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aInput == null || aOutput == null) return F; + GT_Utility.removeSimpleIC2MachineRecipe(aInput, getExtractorRecipeList(), null); + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.extractor, aInput, T)) return F; + GT_Utility.addSimpleIC2MachineRecipe(aInput, getExtractorRecipeList(), null, aOutput); + return T; + } + + /** + * RC-BlastFurnace Recipes + */ + public static boolean addRCBlastFurnaceRecipe(ItemStack aInput, ItemStack aOutput, int aTime) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aInput == null || aOutput == null || aTime <= 0) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rcblastfurnace, aInput, T)) return F; + aInput = GT_Utility.copy(aInput); + aOutput = GT_Utility.copy(aOutput); + try { + mods.railcraft.api.crafting.RailcraftCraftingManager.blastFurnace.addRecipe(aInput, T, F, aTime, aOutput); + } catch (Throwable e) { + return F; + } + return T; + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1) { + return addPulverisationRecipe(aInput, aOutput1, null, 0, F); + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2) { + return addPulverisationRecipe(aInput, aOutput1, aOutput2, 100, F); + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, int aChance) { + return addPulverisationRecipe(aInput, aOutput1, aOutput2, aChance, F); + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, boolean aOverwrite) { + return addPulverisationRecipe(aInput, aOutput1, null, 0, aOverwrite); + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, boolean aOverwrite) { + return addPulverisationRecipe(aInput, aOutput1, aOutput2, 100, aOverwrite); + } + + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, int aChance, boolean aOverwrite) { + return addPulverisationRecipe(aInput, aOutput1, aOutput2, aChance, null, 0, aOverwrite); + } + + /** + * Adds Several Pulverizer-Type Recipes. + */ + public static boolean addPulverisationRecipe(ItemStack aInput, ItemStack aOutput1, ItemStack aOutput2, int aChance2, ItemStack aOutput3, int aChance3, boolean aOverwrite) { + aOutput1 = GT_OreDictUnificator.get(T, aOutput1); + aOutput2 = GT_OreDictUnificator.get(T, aOutput2); + if (GT_Utility.isStackInvalid(aInput) || GT_Utility.isStackInvalid(aOutput1)) return F; + GT_Utility.removeSimpleIC2MachineRecipe(aInput, getMaceratorRecipeList(), null); + + if (GT_Utility.getContainerItem(aInput, F) == null) { + if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.maceration, aInput, T)) { + GT_Utility.addSimpleIC2MachineRecipe(aInput, getMaceratorRecipeList(), null, aOutput1); + } + + RA.addPulveriserRecipe(aInput, new ItemStack[] {aOutput1, aOutput2, aOutput3}, new int[] {10000, aChance2<=0?1000:100*aChance2, aChance3<=0?1000:100*aChance3}, 400, 2); + + if (!OrePrefixes.log.contains(aInput)) { + if (Materials.Wood.contains(aOutput1)) { + if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, T)) { + if (aOutput2 == null) + ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1)); + else + ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2<=0?10:aChance2); + } + } else { + if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rockcrushing, aInput, T)) { + try { + if (GT_Utility.getBlockFromStack(aInput) != Blocks.obsidian && GT_Utility.getBlockFromStack(aInput) != Blocks.gravel) { + mods.railcraft.api.crafting.IRockCrusherRecipe tRecipe = mods.railcraft.api.crafting.RailcraftCraftingManager.rockCrusher.createNewRecipe(GT_Utility.copyAmount(1, aInput), aInput.getItemDamage() != W, F); + tRecipe.addOutput(GT_Utility.copy(aOutput1), 1.0F/aInput.stackSize); + if (aOutput2 != null) tRecipe.addOutput(GT_Utility.copy(aOutput2), (0.01F*(aChance2<=0?10:aChance2))/aInput.stackSize); + if (aOutput3 != null) tRecipe.addOutput(GT_Utility.copy(aOutput3), (0.01F*(aChance3<=0?10:aChance3))/aInput.stackSize); + } + } catch(Throwable e) {/*Do nothing*/} + } + if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, T)) { + if (aOutput2 == null) + ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1)); + else + ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2<=0?10:aChance2); + } + } + } + } + return T; + } + + /** + * Adds a Recipe to the Sawmills of GregTech and ThermalCraft + */ + public static boolean addSawmillRecipe(ItemStack aInput1, ItemStack aOutput1, ItemStack aOutput2) { + aOutput1 = GT_OreDictUnificator.get(T, aOutput1); + aOutput2 = GT_OreDictUnificator.get(T, aOutput2); + if (aInput1 == null || aOutput1 == null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.sawmill, aInput1, T)) return F; + try { + ThermalExpansion.addSawmillRecipe(1600, aInput1, aOutput1, aOutput2, 100); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Induction Smelter Recipes and Alloy Smelter Recipes + */ + public static boolean addAlloySmelterRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, int aDuration, int aEUt, boolean aAllowSecondaryInputEmpty) { + if (aInput1 == null || (aInput2 == null && !aAllowSecondaryInputEmpty) || aOutput1 == null) return F; + aOutput1 = GT_OreDictUnificator.get(T, aOutput1); + boolean temp = F; + if (RA.addAlloySmelterRecipe(aInput1, aInput2, aOutput1, aDuration, aEUt)) temp = T; + if (addInductionSmelterRecipe(aInput1, aInput2, aOutput1, null, aDuration * aEUt * 2, 0)) temp = T; + return temp; + } + + /** + * Induction Smelter Recipes for TE + */ + public static boolean addInductionSmelterRecipe(ItemStack aInput1, ItemStack aInput2, ItemStack aOutput1, ItemStack aOutput2, int aEnergy, int aChance) { + aOutput1 = GT_OreDictUnificator.get(T, aOutput1); + aOutput2 = GT_OreDictUnificator.get(T, aOutput2); + if (aInput1 == null || aOutput1 == null || GT_Utility.getContainerItem(aInput1, F) != null) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.inductionsmelter, aInput2==null?aInput1:aOutput1, T)) return F; + try { + ThermalExpansion.addSmelterRecipe(aEnergy*10, GT_Utility.copy(aInput1), aInput2==null?new ItemStack(Blocks.sand, 1, 0):aInput2, aOutput1, aOutput2, aChance); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Smelts Ores to Ingots + */ + public static boolean addOreToIngotSmeltingRecipe(ItemStack aInput, ItemStack aOutput) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aInput == null || aOutput == null) return F; + FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F); + return T; + } + + private static Map<IRecipeInput, RecipeOutput> sExtractorRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + private static Map<IRecipeInput, RecipeOutput> sMaceratorRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + private static Map<IRecipeInput, RecipeOutput> sCompressorRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + private static Map<IRecipeInput, RecipeOutput> sOreWashingRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + private static Map<IRecipeInput, RecipeOutput> sThermalCentrifugeRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + private static Map<IRecipeInput, RecipeOutput> sMassfabRecipes = new HashMap<IRecipeInput, RecipeOutput>(); + + public static Map<IRecipeInput, RecipeOutput> getExtractorRecipeList() { + try { + return ic2.api.recipe.Recipes.extractor.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sExtractorRecipes; + } + + public static Map<IRecipeInput, RecipeOutput> getCompressorRecipeList() { + try { + return ic2.api.recipe.Recipes.compressor.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sCompressorRecipes; + } + + public static Map<IRecipeInput, RecipeOutput> getMaceratorRecipeList() { + try { + return ic2.api.recipe.Recipes.macerator.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sMaceratorRecipes; + } + + public static Map<IRecipeInput, RecipeOutput> getThermalCentrifugeRecipeList() { + try { + return ic2.api.recipe.Recipes.centrifuge.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sThermalCentrifugeRecipes; + } + + public static Map<IRecipeInput, RecipeOutput> getOreWashingRecipeList() { + try { + return ic2.api.recipe.Recipes.oreWashing.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sOreWashingRecipes; + } + + public static Map<IRecipeInput, RecipeOutput> getMassFabricatorList() { + try { + return ic2.api.recipe.Recipes.matterAmplifier.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sMassfabRecipes; + } + + /** + * IC2-ThermalCentrifuge Recipe. Overloads old Recipes automatically + */ + public static boolean addThermalCentrifugeRecipe(ItemStack aInput, int aHeat, Object... aOutput) { + if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return F; + GT_Utility.removeSimpleIC2MachineRecipe(aInput, getThermalCentrifugeRecipeList(), null); + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.thermalcentrifuge, aInput, T)) return F; + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setInteger("minHeat", aHeat); + GT_Utility.addSimpleIC2MachineRecipe(aInput, getThermalCentrifugeRecipeList(), tNBT, aOutput); + return T; + } + + /** + * IC2-OreWasher Recipe. Overloads old Recipes automatically + */ + public static boolean addOreWasherRecipe(ItemStack aInput, int aWaterAmount, Object... aOutput) { + if (aInput == null || aOutput == null || aOutput.length <= 0 || aOutput[0] == null) return F; + GT_Utility.removeSimpleIC2MachineRecipe(aInput, getOreWashingRecipeList(), null); + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.orewashing, aInput, T)) return F; + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setInteger("amount", aWaterAmount); + GT_Utility.addSimpleIC2MachineRecipe(aInput, getOreWashingRecipeList(), tNBT, aOutput); + return T; + } + + /** + * IC2-Compressor Recipe. Overloads old Recipes automatically + */ + public static boolean addCompressionRecipe(ItemStack aInput, ItemStack aOutput) { + aOutput = GT_OreDictUnificator.get(T, aOutput); + if (aInput == null || aOutput == null) return F; + GT_Utility.removeSimpleIC2MachineRecipe(aInput, getCompressorRecipeList(), null); + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.compression, aInput, T)) return F; + GT_Utility.addSimpleIC2MachineRecipe(aInput, getCompressorRecipeList(), null, aOutput); + return T; + } + + /** + * @param aValue Scrap = 5000, Scrapbox = 45000, Diamond Dust 125000 + */ + public static boolean addIC2MatterAmplifier(ItemStack aAmplifier, int aValue) { + if (aAmplifier == null || aValue <= 0) return F; + if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.massfabamplifier, aAmplifier, T)) return F; + try { + NBTTagCompound tNBT = new NBTTagCompound(); + tNBT.setInteger("amplification", aValue); + GT_Utility.callMethod(ic2.api.recipe.Recipes.matterAmplifier, "addRecipe", F, F, F, aAmplifier, tNBT); + } catch(Throwable e) {/*Do nothing*/} + return T; + } + + /** + * Rolling Machine Crafting Recipe + */ + public static boolean addRollingMachineRecipe(ItemStack aResult, Object[] aRecipe) { + aResult = GT_OreDictUnificator.get(T, aResult); + if (aResult == null || aRecipe == null || aResult.stackSize <= 0) return F; + try { + mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copy(aResult), aRecipe)); + } catch(Throwable e) { + return addCraftingRecipe(GT_Utility.copy(aResult), aRecipe); + } + return T; + } + + private static boolean sBufferCraftingRecipes = T; + private static final List<IRecipe> sAllRecipeList = Collections.synchronizedList(new ArrayList<IRecipe>(5000)), sBufferRecipeList = new ArrayList<IRecipe>(1000); + public static final List<IRecipe> sSingleNonBlockDamagableRecipeList = new ArrayList<IRecipe>(1000); + + public static void stopBufferingCraftingRecipes() { + sBufferCraftingRecipes = F; + for (IRecipe tRecipe : sBufferRecipeList) GameRegistry.addRecipe(tRecipe); + sBufferRecipeList.clear(); + } + + public static class RecipeBits { + /** Mirrors the Recipe */ + public static long MIRRORED = B[0]; + /** Buffers the Recipe for later addition. This makes things more efficient. */ + public static long BUFFERED = B[1]; + /** This is a special Tag I used for crafting Coins up and down. */ + public static long KEEPNBT = B[2]; + /** Makes the Recipe Reverse Craftable in the Disassembler. */ + public static long DISMANTLEABLE = B[3]; + /** Prevents the Recipe from accidentally getting removed by my own Handlers. */ + public static long NOT_REMOVABLE = B[4]; + /** Reverses the Output of the Recipe for smelting and pulverising. */ + public static long REVERSIBLE = B[5]; + /** Removes all Recipes with the same Output Item regardless of NBT, unless another Recipe Deletion Bit is added too. */ + public static long DELETE_ALL_OTHER_RECIPES = B[6]; + /** Removes all Recipes with the same Output Item limited to the same NBT. */ + public static long DELETE_ALL_OTHER_RECIPES_IF_SAME_NBT = B[7]; + /** Removes all Recipes with the same Output Item limited to Shaped Recipes. */ + public static long DELETE_ALL_OTHER_SHAPED_RECIPES = B[8]; + /** Removes all Recipes with the same Output Item limited to native Recipe Handlers. */ + public static long DELETE_ALL_OTHER_NATIVE_RECIPES = B[9]; + /** Disables the check for colliding Recipes. */ + public static long DO_NOT_CHECK_FOR_COLLISIONS = B[10]; + /** Only adds the Recipe if there is another Recipe having that Output */ + public static long ONLY_ADD_IF_THERE_IS_ANOTHER_RECIPE_FOR_IT = B[11]; + /** Only adds the Recipe if it has an Output */ + public static long ONLY_ADD_IF_RESULT_IS_NOT_NULL = B[12]; + } + + /** + * Shapeless Crafting Recipes. Deletes conflicting Recipes too. + */ + public static boolean addCraftingRecipe(ItemStack aResult, Enchantment[] aEnchantmentsAdded, int[] aEnchantmentLevelsAdded, Object[] aRecipe) { + return addCraftingRecipe(aResult, aEnchantmentsAdded, aEnchantmentLevelsAdded, F, T, F, F, F, F, F, F, F, F, F, F, T, aRecipe); + } + + /** + * Regular Crafting Recipes. Deletes conflicting Recipes too. + * + * You can insert instances of IItemContainer into the Recipe Input Array directly without having to call "get(1)" on them. + * + * Enums are automatically getting their "name()"-Method called in order to deliver an OreDict String. + * + * Lowercase Letters are reserved for Tools. They are as follows: + * + * 'b' ToolDictNames.craftingToolBlade + * 'c' ToolDictNames.craftingToolCrowbar, + * 'd' ToolDictNames.craftingToolScrewdriver, + * 'f' ToolDictNames.craftingToolFile, + * 'h' ToolDictNames.craftingToolHardHammer, + * 'i' ToolDictNames.craftingToolSolderingIron, + * 'j' ToolDictNames.craftingToolSolderingMetal, + * 'k' ToolDictNames.craftingToolKnive + * 'm' ToolDictNames.craftingToolMortar, + * 'p' ToolDictNames.craftingToolDrawplate, + * 'r' ToolDictNames.craftingToolSoftHammer, + * 's' ToolDictNames.craftingToolSaw, + * 'w' ToolDictNames.craftingToolWrench, + * 'x' ToolDictNames.craftingToolWireCutter, + */ + public static boolean addCraftingRecipe(ItemStack aResult, Object[] aRecipe) { + return addCraftingRecipe(aResult, 0, aRecipe); + } + + /** + * Regular Crafting Recipes. Deletes conflicting Recipes too. + * + * You can insert instances of IItemContainer into the Recipe Input Array directly without having to call "get(1)" on them. + * + * Enums are automatically getting their "name()"-Method called in order to deliver an OreDict String. + * + * Lowercase Letters are reserved for Tools. They are as follows: + * + * 'b' ToolDictNames.craftingToolBlade + * 'c' ToolDictNames.craftingToolCrowbar, + * 'd' ToolDictNames.craftingToolScrewdriver, + * 'f' ToolDictNames.craftingToolFile, + * 'h' ToolDictNames.craftingToolHardHammer, + * 'i' ToolDictNames.craftingToolSolderingIron, + * 'j' ToolDictNames.craftingToolSolderingMetal, + * 'k' ToolDictNames.craftingToolKnive + * 'm' ToolDictNames.craftingToolMortar, + * 'p' ToolDictNames.craftingToolDrawplate, + * 'r' ToolDictNames.craftingToolSoftHammer, + * 's' ToolDictNames.craftingToolSaw, + * 'w' ToolDictNames.craftingToolWrench, + * 'x' ToolDictNames.craftingToolWireCutter, + */ + public static boolean addCraftingRecipe(ItemStack aResult, long aBitMask, Object[] aRecipe) { + return addCraftingRecipe(aResult, new Enchantment[0], new int[0], (aBitMask & RecipeBits.MIRRORED) != 0, (aBitMask & RecipeBits.BUFFERED) != 0, (aBitMask & RecipeBits.KEEPNBT) != 0, (aBitMask & RecipeBits.DISMANTLEABLE) != 0, (aBitMask & RecipeBits.NOT_REMOVABLE) == 0, (aBitMask & RecipeBits.REVERSIBLE) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_RECIPES_IF_SAME_NBT) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_SHAPED_RECIPES) != 0, (aBitMask & RecipeBits.DELETE_ALL_OTHER_NATIVE_RECIPES) != 0, (aBitMask & RecipeBits.DO_NOT_CHECK_FOR_COLLISIONS) == 0, (aBitMask & RecipeBits.ONLY_ADD_IF_THERE_IS_ANOTHER_RECIPE_FOR_IT) != 0, (aBitMask & RecipeBits.ONLY_ADD_IF_RESULT_IS_NOT_NULL) != 0, aRecipe); + } + + /** + * Internal realisation of the Crafting Recipe adding Process. + */ + private static boolean addCraftingRecipe(ItemStack aResult, Enchantment[] aEnchantmentsAdded, int[] aEnchantmentLevelsAdded, boolean aMirrored, boolean aBuffered, boolean aKeepNBT, boolean aDismantleable, boolean aRemovable, boolean aReversible, boolean aRemoveAllOthersWithSameOutput, boolean aRemoveAllOthersWithSameOutputIfTheyHaveSameNBT, boolean aRemoveAllOtherShapedsWithSameOutput, boolean aRemoveAllOtherNativeRecipes, boolean aCheckForCollisions, boolean aOnlyAddIfThereIsAnyRecipeOutputtingThis, boolean aOnlyAddIfResultIsNotNull, Object[] aRecipe) { + aResult = GT_OreDictUnificator.get(T, aResult); + if (aOnlyAddIfResultIsNotNull && aResult == null) return F; + if (aResult != null && Items.feather.getDamage(aResult) == W) Items.feather.setDamage(aResult, 0); + if (aRecipe == null || aRecipe.length <= 0) return F; + + boolean tThereWasARecipe = F; + + for (byte i = 0; i < aRecipe.length; i++) { + if (aRecipe[i] instanceof IItemContainer) + aRecipe[i] = ((IItemContainer)aRecipe[i]).get(1); + else if (aRecipe[i] instanceof Enum) + aRecipe[i] = ((Enum)aRecipe[i]).name(); + else if (!(aRecipe[i] == null || aRecipe[i] instanceof ItemStack || aRecipe[i] instanceof ItemData || aRecipe[i] instanceof String || aRecipe[i] instanceof Character)) + aRecipe[i] = aRecipe[i].toString(); + } + + try { + String shape = E; + int idx = 0; + if (aRecipe[idx] instanceof Boolean) { + throw new IllegalArgumentException(); + } + + ArrayList<Object> tRecipeList = new ArrayList<Object>(Arrays.asList(aRecipe)); + + while (aRecipe[idx] instanceof String) { + String s = (String)aRecipe[idx++]; + shape += s; + while (s.length() < 3) s+=" "; + if (s.length() > 3) throw new IllegalArgumentException(); + + for (char c : s.toCharArray()) { + switch(c) { + case 'b': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolBlade .name()); break; + case 'c': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolCrowbar .name()); break; + case 'd': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolScrewdriver .name()); break; + case 'f': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolFile .name()); break; + case 'h': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolHardHammer .name()); break; + case 'i': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolSolderingIron .name()); break; + case 'j': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolSolderingMetal .name()); break; + case 'k': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolKnife .name()); break; + case 'm': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolMortar .name()); break; + case 'p': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolDrawplate .name()); break; + case 'r': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolSoftHammer .name()); break; + case 's': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolSaw .name()); break; + case 'w': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolWrench .name()); break; + case 'x': tRecipeList.add(c); tRecipeList.add(ToolDictNames.craftingToolWireCutter .name()); break; + } + } + } + + aRecipe = tRecipeList.toArray(); + + if (aRecipe[idx] instanceof Boolean) { + idx++; + } + HashMap<Character, ItemStack> tItemStackMap = new HashMap<Character, ItemStack>(); + HashMap<Character, ItemData> tItemDataMap = new HashMap<Character, ItemData>(); + tItemStackMap.put(' ', null); + + boolean tRemoveRecipe = T; + + for (; idx < aRecipe.length; idx += 2) { + if (aRecipe[idx] == null || aRecipe[idx + 1] == null) { + if (D1) { + GT_Log.err.println("WARNING: Missing Item for shaped Recipe: " + (aResult==null?"null":aResult.getDisplayName())); + for (Object tContent : aRecipe) GT_Log.err.println(tContent); + } + return F; + } + Character chr = (Character)aRecipe[idx]; + Object in = aRecipe[idx + 1]; + if (in instanceof ItemStack) { + tItemStackMap.put(chr, GT_Utility.copy((ItemStack)in)); + tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack)in)); + } else if (in instanceof ItemData) { + String tString = in.toString(); + if (tString.equals("plankWood")) { + tItemDataMap.put(chr, new ItemData(Materials.Wood, M)); + } else if (tString.equals("stoneNetherrack")) { + tItemDataMap.put(chr, new ItemData(Materials.Netherrack, M)); + } else if (tString.equals("stoneObsidian")) { + tItemDataMap.put(chr, new ItemData(Materials.Obsidian, M)); + } else if (tString.equals("stoneEndstone")) { + tItemDataMap.put(chr, new ItemData(Materials.Endstone, M)); + } else { + tItemDataMap.put(chr, (ItemData)in); + } + ItemStack tStack = GT_OreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = F; else tItemStackMap.put(chr, tStack); + in = aRecipe[idx + 1] = in.toString(); + } else if (in instanceof String) { + if (in.equals(OreDictNames.craftingChest .toString())) tItemDataMap.put(chr, new ItemData(Materials.Wood, M * 8)); + else if (in.equals(OreDictNames.craftingBook .toString())) tItemDataMap.put(chr, new ItemData(Materials.Paper, M * 3)); + else if (in.equals(OreDictNames.craftingPiston .toString())) tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 4, Materials.Wood, M * 3)); + else if (in.equals(OreDictNames.craftingFurnace .toString())) tItemDataMap.put(chr, new ItemData(Materials.Stone, M * 8)); + else if (in.equals(OreDictNames.craftingIndustrialDiamond .toString())) tItemDataMap.put(chr, new ItemData(Materials.Diamond, M)); + else if (in.equals(OreDictNames.craftingAnvil .toString())) tItemDataMap.put(chr, new ItemData(Materials.Iron, M * 10)); + ItemStack tStack = GT_OreDictUnificator.getFirstOre(in, 1); + if (tStack == null) tRemoveRecipe = F; else tItemStackMap.put(chr, tStack); + } else { + throw new IllegalArgumentException(); + } + } + + if (aReversible && aResult != null) { + ItemData[] tData = new ItemData[9]; + int x = -1; + for (char chr : shape.toCharArray()) tData[++x] = tItemDataMap.get(chr); + if (GT_Utility.arrayContainsNonNull(tData)) GT_OreDictUnificator.addItemData(aResult, new ItemData(tData)); + } + + if (aCheckForCollisions && tRemoveRecipe) { + ItemStack[] tRecipe = new ItemStack[9]; + int x = -1; |
