From 1185424fa7c692f9932623b965a99392d969e3c5 Mon Sep 17 00:00:00 2001 From: Shawn Buckley Date: Wed, 21 Oct 2015 20:46:52 -0400 Subject: Move source files --- src/main/java/gregtech/api/util/GT_BaseCrop.java | 129 ++ .../gregtech/api/util/GT_CircuitryBehavior.java | 178 ++ src/main/java/gregtech/api/util/GT_Config.java | 86 + .../java/gregtech/api/util/GT_CoverBehavior.java | 217 +++ .../java/gregtech/api/util/GT_CreativeTab.java | 24 + src/main/java/gregtech/api/util/GT_FoodStat.java | 102 ++ .../java/gregtech/api/util/GT_IBoxableWrapper.java | 12 + .../api/util/GT_ItsNotMyFaultException.java | 16 + .../java/gregtech/api/util/GT_LanguageManager.java | 95 ++ src/main/java/gregtech/api/util/GT_Log.java | 35 + src/main/java/gregtech/api/util/GT_ModHandler.java | 1727 +++++++++++++++++++ .../gregtech/api/util/GT_OreDictUnificator.java | 332 ++++ .../java/gregtech/api/util/GT_PlayedSound.java | 28 + src/main/java/gregtech/api/util/GT_Recipe.java | 1046 ++++++++++++ .../gregtech/api/util/GT_RecipeRegistrator.java | 313 ++++ .../java/gregtech/api/util/GT_Shaped_Recipe.java | 95 ++ .../gregtech/api/util/GT_Shapeless_Recipe.java | 95 ++ .../gregtech/api/util/GT_SpawnEventHandler.java | 46 + src/main/java/gregtech/api/util/GT_Utility.java | 1791 ++++++++++++++++++++ 19 files changed, 6367 insertions(+) create mode 100644 src/main/java/gregtech/api/util/GT_BaseCrop.java create mode 100644 src/main/java/gregtech/api/util/GT_CircuitryBehavior.java create mode 100644 src/main/java/gregtech/api/util/GT_Config.java create mode 100644 src/main/java/gregtech/api/util/GT_CoverBehavior.java create mode 100644 src/main/java/gregtech/api/util/GT_CreativeTab.java create mode 100644 src/main/java/gregtech/api/util/GT_FoodStat.java create mode 100644 src/main/java/gregtech/api/util/GT_IBoxableWrapper.java create mode 100644 src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java create mode 100644 src/main/java/gregtech/api/util/GT_LanguageManager.java create mode 100644 src/main/java/gregtech/api/util/GT_Log.java create mode 100644 src/main/java/gregtech/api/util/GT_ModHandler.java create mode 100644 src/main/java/gregtech/api/util/GT_OreDictUnificator.java create mode 100644 src/main/java/gregtech/api/util/GT_PlayedSound.java create mode 100644 src/main/java/gregtech/api/util/GT_Recipe.java create mode 100644 src/main/java/gregtech/api/util/GT_RecipeRegistrator.java create mode 100644 src/main/java/gregtech/api/util/GT_Shaped_Recipe.java create mode 100644 src/main/java/gregtech/api/util/GT_Shapeless_Recipe.java create mode 100644 src/main/java/gregtech/api/util/GT_SpawnEventHandler.java create mode 100644 src/main/java/gregtech/api/util/GT_Utility.java (limited to 'src/main/java/gregtech/api/util') diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java new file mode 100644 index 0000000000..e7cef2c598 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -0,0 +1,129 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.E; +import gregtech.api.enums.ConfigCategories; +import ic2.api.crops.CropCard; +import ic2.api.crops.Crops; +import ic2.api.crops.ICropTile; + +import java.util.ArrayList; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; + +public class GT_BaseCrop extends CropCard { + private String mName = E, mDiscoveredBy = "Gregorius Techneticies", mAttributes[]; + private int mTier = 0, mMaxSize = 0, mAfterHarvestSize = 0, mHarvestSize = 0, mStats[] = new int[5]; + private ItemStack mDrop = null, mSpecialDrops[] = null; + + public static ArrayList sCropList = new ArrayList(); + + /** + * To create new Crops + * @param aID Default ID + * @param aCropName Name of the Crop + * @param aDiscoveredBy The one who discovered the Crop + * @param aDrop The Item which is dropped by the Crop. must be != null + * @param aBaseSeed Baseseed to plant this Crop. null == crossbreed only + * @param aTier tier of the Crop. forced to be >= 1 + * @param aMaxSize maximum Size of the Crop. forced to be >= 3 + * @param aGrowthSpeed how fast the Crop grows. if < 0 then its set to Tier*300 + * @param aHarvestSize the size the Crop needs to be harvested. forced to be between 2 and max size + */ + public GT_BaseCrop(int aID, String aCropName, String aDiscoveredBy, ItemStack aDrop, ItemStack[] aSpecialDrops, ItemStack aBaseSeed, int aTier, int aMaxSize, int aGrowthSpeed, int aAfterHarvestSize, int aHarvestSize, int aStatChemical, int aStatFood, int aStatDefensive, int aStatColor, int aStatWeed, String[] aAttributes) { + mName = aCropName; + aID = GT_Config.addIDConfig(ConfigCategories.IDs.crops, mName.replaceAll(" ", "_"), aID); + if (aDiscoveredBy != null && !aDiscoveredBy.equals(E)) mDiscoveredBy = aDiscoveredBy; + if (aDrop != null && aID > 0 && aID < 256) { + mDrop = GT_Utility.copy(aDrop); + mSpecialDrops = aSpecialDrops; + mTier = Math.max(1, aTier); + mMaxSize = Math.max(3, aMaxSize); +// mGrowthSpeed = aGrowthSpeed>0?aGrowthSpeed:mTier*300; + mHarvestSize = Math.min(Math.max(aHarvestSize, 2), mMaxSize); + mAfterHarvestSize = Math.min(Math.max(aAfterHarvestSize, 1), mMaxSize-1); + mStats[0] = aStatChemical; + mStats[1] = aStatFood; + mStats[2] = aStatDefensive; + mStats[3] = aStatColor; + mStats[4] = aStatWeed; + mAttributes = aAttributes; + if (!Crops.instance.registerCrop(this, aID)) throw new GT_ItsNotMyFaultException("Make sure the Crop ID is valid!"); + if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, aID, 1, 1, 1, 1); + sCropList.add(this); + } + } + + @Override + public byte getSizeAfterHarvest(ICropTile crop) { + return (byte)mAfterHarvestSize; + } + + @Override + public String[] attributes() { + return mAttributes; + } + + @Override + public String discoveredBy() { + return mDiscoveredBy; + } + + @Override + public final boolean canGrow(ICropTile aCrop) { + return aCrop.getSize() < maxSize(); + } + + @Override + public final boolean canBeHarvested(ICropTile aCrop) { + return aCrop.getSize() >= mHarvestSize; + } + + @Override + public boolean canCross(ICropTile aCrop) { + return aCrop.getSize() + 2 > maxSize(); + } + + @Override + public int stat(int n) { + if (n < 0 || n >= mStats.length) return 0; + return mStats[n]; + } + + @Override + public String name() { + return mName; + } + + @Override + public int tier() { + return mTier; + } + + @Override + public int maxSize() { + return mMaxSize; + } + + @Override + public ItemStack getGain(ICropTile aCrop) { + int tDrop = 0; + if (mSpecialDrops != null && (tDrop = new Random().nextInt(mSpecialDrops.length+4)) < mSpecialDrops.length && mSpecialDrops[tDrop] != null) { + return GT_Utility.copy(mSpecialDrops[tDrop]); + } + return GT_Utility.copy(mDrop); + } + + @Override + public boolean rightclick(ICropTile aCrop, EntityPlayer aPlayer) { + if (!canBeHarvested(aCrop)) return false; + return aCrop.harvest(aPlayer==null?false:aPlayer instanceof EntityPlayerMP); + } + + @Override + public int getOptimalHavestSize(ICropTile crop) { + return maxSize(); + } +} diff --git a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java new file mode 100644 index 0000000000..6cda3c202f --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java @@ -0,0 +1,178 @@ +package gregtech.api.util; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IRedstoneCircuitBlock; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * Redstone Circuit Control Code + * + * This should make everything possible what a Redstone Computer or BuildCraft Gate could do. + * It is intended to use this similar to BC-Gates (for acquiring Data) and RP Logic Gates. + * You could write an extremely specified and complex Logic Gate, which works only for you Setup, like + * with ComputerCraft, but you would have to write an extra Mod to add that, as it doesn't work Ingame. + * + * One can make use of the fact, that ItemStacks can be stored as Integer, so that you can scan + * Inventories for specific Items using that. Luckily the Buttons in the GUI enable Copy/Paste of + * ItemID+MetaData to Integer, including the WildCard Damage Value when you use rightclick to place it. + * You just need to use @GT_Utility.stackToInt(ItemStack aStack) to get it. + * + * All Functions run usually in a seperate try/catch Block, so that failed Logic won't crash the TileEntity. + */ +public abstract class GT_CircuitryBehavior { + /** + * @param aIndex 0 - 1023 are my own Indices, so use other Numbers! + */ + public GT_CircuitryBehavior(int aIndex) { + GregTech_API.sCircuitryBehaviors.put(aIndex, this); + } + + /** + * Initializes the Parameters of this Circuit, all Parameters have been set to 0 right before calling this + * @param aCircuitData, The Data Storage you can use (8 Slots) + * @param aRedstoneCircuitBlock, The Circuit Block MetaTileEntity itself + */ + public abstract void initParameters(int[] aCircuitData, IRedstoneCircuitBlock aRedstoneCircuitBlock); + + /** + * Validates the Parameters of this Circuit when a value has been changed by the GUI + * Also called right after @initParameters and when the Chunk reloads + * @param aCircuitData, The Data Storage you can use (8 Slots and only the first 4 are User definable) + * @param aRedstoneCircuitBlock, The Circuit Block MetaTileEntity itself + */ + public abstract void validateParameters(int[] aCircuitData, IRedstoneCircuitBlock aRedstoneCircuitBlock); + + /** + * Called every tick if the Block has enough Energy and if the Block is Active + * @param aCircuitData, The Data Storage you can use (8 Slots) + * @param aRedstoneCircuitBlock, The Circuit Block MetaTileEntity itself + */ + public abstract void onTick(int[] aCircuitData, IRedstoneCircuitBlock aRedstoneCircuitBlock); + + /** + * If the ItemStack should be displayed. Parameters are between 0 and 3. + */ + public abstract boolean displayItemStack(int[] aCircuitData, IRedstoneCircuitBlock aRedstoneCircuitBlock, int aIndex); + + /***************** + * GUI Functions * + *****************/ + + /** + * The Name of the Gate for the GUI + */ + @SideOnly(Side.CLIENT) + public abstract String getName(); + + /** + * The Description of the Gate for the GUI + */ + @SideOnly(Side.CLIENT) + public abstract String getDescription(); + + /** + * The Description of the Data Field for the GUI + */ + @SideOnly(Side.CLIENT) + public abstract String getDataDescription(int[] aCircuitData, int aCircuitDataIndex); + + /** + * How the Integer should be displayed in the GUI. + * null means, that it just displays as regular Number. + */ + @SideOnly(Side.CLIENT) + public String getDataDisplay(int[] aCircuitData, int aCircuitDataIndex) { + return null; + } + + + /**************************** + * Useful Utility Functions * + ****************************/ + + /** + * returns if there is Redstone applied to any of the valid Inputs (OR) + */ + public static final boolean getAnyRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) { + return true; + } + } + } + return false; + } + + /** + * returns if there is Redstone applied to all the valid Inputs (AND) + */ + public static final boolean getAllRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + if (aRedstoneCircuitBlock.getInputRedstone(i) == 0) { + return false; + } + } + } + return true; + } + + /** + * returns if there is Redstone applied to exactly one of the valid Inputs (XOR) + */ + public static final boolean getOneRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + int tRedstoneAmount = 0; + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) { + tRedstoneAmount++; + } + } + } + return tRedstoneAmount == 1; + } + + /** + * returns the strongest incoming RS-Power + */ + public static final byte getStrongestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + byte tRedstoneAmount = 0; + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + tRedstoneAmount = (byte)Math.max(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + } + } + return tRedstoneAmount; + } + + /** + * returns the weakest incoming non-zero RS-Power + */ + public static final byte getWeakestNonZeroRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; + byte tRedstoneAmount = 15; + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + if (aRedstoneCircuitBlock.getInputRedstone(i) > 0) + tRedstoneAmount = (byte)Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + } + } + return tRedstoneAmount; + } + + /** + * returns the weakest incoming RS-Power + */ + public static final byte getWeakestRedstone(IRedstoneCircuitBlock aRedstoneCircuitBlock) { + if (!getAnyRedstone(aRedstoneCircuitBlock)) return 0; + byte tRedstoneAmount = 15; + for (byte i = 0; i < 6; i++) { + if (i != aRedstoneCircuitBlock.getOutputFacing() && aRedstoneCircuitBlock.getCover(i).letsRedstoneGoIn(i, aRedstoneCircuitBlock.getCoverID(i), aRedstoneCircuitBlock.getCoverVariable(i), aRedstoneCircuitBlock.getOwnTileEntity())) { + tRedstoneAmount = (byte)Math.min(tRedstoneAmount, aRedstoneCircuitBlock.getInputRedstone(i)); + } + } + return tRedstoneAmount; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_Config.java b/src/main/java/gregtech/api/util/GT_Config.java new file mode 100644 index 0000000000..9ad2ebab50 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_Config.java @@ -0,0 +1,86 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.E; +import static gregtech.api.enums.GT_Values.F; +import gregtech.api.GregTech_API; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +public class GT_Config implements Runnable { + public static boolean troll = F; + + public static Configuration sConfigFileIDs; + + public static int addIDConfig(Object aCategory, String aName, int aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = sConfigFileIDs.get(aCategory.toString().replaceAll("\\|", "."), aName.replaceAll("\\|", "."), aDefault); + int rResult = tProperty.getInt(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sConfigFileIDs.save(); + return rResult; + } + + public final Configuration mConfig; + + public GT_Config(Configuration aConfig) { + mConfig = aConfig; + mConfig.load(); + mConfig.save(); + GregTech_API.sAfterGTPreload.add(this); // in case of crash on startup + GregTech_API.sAfterGTLoad.add(this); // in case of crash on startup + GregTech_API.sAfterGTPostload.add(this); + } + + public static String getStackConfigName(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return E; + Object rName = GT_OreDictUnificator.getAssociation(aStack); + if (rName != null) return rName.toString(); + try {if (GT_Utility.isStringValid(rName = aStack.getUnlocalizedName())) return rName.toString();} catch (Throwable e) {/*Do nothing*/} + String sName = aStack.getItem().toString(); + String[] tmp = sName.split("@"); + if(tmp.length>0)sName=tmp[0]; + return sName + "." + aStack.getItemDamage(); + } + + public boolean get(Object aCategory, ItemStack aStack, boolean aDefault) { + String aName = getStackConfigName(aStack); + return get(aCategory, aName , aDefault); + } + + public boolean get(Object aCategory, String aName, boolean aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName+"_"+aDefault).replaceAll("\\|", "_"), aDefault); + boolean rResult = tProperty.getBoolean(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + public int get(Object aCategory, ItemStack aStack, int aDefault) { + return get(aCategory, getStackConfigName(aStack), aDefault); + } + + public int get(Object aCategory, String aName, int aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName+"_"+aDefault).replaceAll("\\|", "_"), aDefault); + int rResult = tProperty.getInt(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + public double get(Object aCategory, ItemStack aStack, double aDefault) { + return get(aCategory, getStackConfigName(aStack), aDefault); + } + + public double get(Object aCategory, String aName, double aDefault) { + if (GT_Utility.isStringInvalid(aName)) return aDefault; + Property tProperty = mConfig.get(aCategory.toString().replaceAll("\\|", "_"), (aName+"_"+aDefault).replaceAll("\\|", "_"), aDefault); + double rResult = tProperty.getDouble(aDefault); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) mConfig.save(); + return rResult; + } + + @Override + public void run() { + mConfig.save(); + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java new file mode 100644 index 0000000000..cfc75f36b8 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java @@ -0,0 +1,217 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.E; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.objects.GT_ItemStack; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; + +/** + * For Covers with a special behavior. + */ +public abstract class GT_CoverBehavior { + /** + * Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time. + */ + public int doCoverThings(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) { + return aCoverVariable; + } + + /** + * Called when someone rightclicks this Cover. + * + * return true, if something actually happens. + */ + public boolean onCoverRightclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * Called when someone rightclicks this Cover Client Side + * + * return true, if something actually happens. + */ + public boolean onCoverRightclickClient(byte aSide, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return false; + } + + /** + * Called when someone rightclicks this Cover with a Screwdriver. Doesn't call @onCoverRightclick in this Case. + * + * return the new Value of the Cover Variable + */ + public int onCoverScrewdriverclick(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, float aY, float aZ) { + return aCoverVariable; + } + + /** + * Checks if the Cover can be placed on this. + */ + public boolean isCoverPlaceable(byte aSide, GT_ItemStack aStack, ICoverable aTileEntity) { + return true; + } + + /** + * Removes the Cover if this returns true, or if aForced is true. + * Doesn't get called when the Machine Block is getting broken, only if you break the Cover away from the Machine. + */ + public boolean onCoverRemoval(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, boolean aForced) { + return true; + } + + /** + * Gives a small Text for the status of the Cover. + */ + public String getDescription(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return E; + } + + /** + * How Blast Proof the Cover is. 30 is normal. + */ + public float getBlastProofLevel(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return 10.0F; + } + + /** + * If it lets RS-Signals into the Block + * + * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public boolean letsRedstoneGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets RS-Signals out of the Block + */ + public boolean letsRedstoneGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals into the Block + * + * This is just Informative so that Machines know if their Redstone Input is blocked or not + */ + public boolean letsFibreGoIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Fibre-Signals out of the Block + */ + public boolean letsFibreGoOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy into the Block + */ + public boolean letsEnergyIn(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Energy out of the Block + */ + public boolean letsEnergyOut(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids into the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public boolean letsFluidIn(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Liquids out of the Block, aFluid can be null meaning if this is generally allowing Fluids or not. + */ + public boolean letsFluidOut(byte aSide, int aCoverID, int aCoverVariable, Fluid aFluid, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items into the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + public boolean letsItemsIn(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets Items out of the Block, aSlot = -1 means if it is generally accepting Items (return false for no Interaction at all), aSlot = -2 means if it would accept for all Slots (return true to skip the Checks for each Slot). + */ + public boolean letsItemsOut(byte aSide, int aCoverID, int aCoverVariable, int aSlot, ICoverable aTileEntity) { + return false; + } + + /** + * If it lets you rightclick the Machine normally + */ + public boolean isGUIClickable(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Needs to return true for Covers, which have a Redstone Output on their Facing. + */ + public boolean manipulatesSidedRedstoneOutput(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * if this Cover should let Pipe Connections look connected even if it is not the case. + */ + public boolean alwaysLookConnected(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return false; + } + + /** + * Called to determine the incoming Redstone Signal of a Machine. + * Returns the original Redstone per default. + * The Cover should @letsRedstoneGoIn or the aInputRedstone Parameter is always 0. + */ + public byte getRedstoneInput(byte aSide, byte aInputRedstone, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return letsRedstoneGoIn(aSide, aCoverID, aCoverVariable, aTileEntity)?aInputRedstone:0; + } + + /** + * Gets the Tick Rate for doCoverThings of the Cover + * + * 0 = No Ticks! Yes, 0 is Default, you have to override this + */ + public int getTickRate(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return 0; + } + + /** + * If this is a simple Cover, which can also be used on Bronze Machines and similar. + */ + public boolean isSimpleCover() { + return false; + } + + /** + * The MC Color of this Lens. -1 for no Color (meaning this isn't a Lens then). + */ + public byte getLensColor(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return -1; + } + + /** + * @return the ItemStack dropped by this Cover + */ + public ItemStack getDrop(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return GT_OreDictUnificator.get(true, aTileEntity.getCoverItemAtSide(aSide)); + } + + /** + * @return sets the Cover upon placement. + */ + public void placeCover(byte aSide, ItemStack aCover, ICoverable aTileEntity) { + aTileEntity.setCoverIDAtSide(aSide, GT_Utility.stackToInt(aCover)); + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_CreativeTab.java b/src/main/java/gregtech/api/util/GT_CreativeTab.java new file mode 100644 index 0000000000..d789fdc8a5 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_CreativeTab.java @@ -0,0 +1,24 @@ +package gregtech.api.util; + +import gregtech.api.enums.ItemList; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class GT_CreativeTab extends CreativeTabs { + public GT_CreativeTab(String aName, String aLocalName) { + super("GregTech." + aName); + GT_LanguageManager.addStringLocalization("itemGroup.GregTech." + aName, aLocalName); + } + + @Override + public ItemStack getIconItemStack() { + return ItemList.Tool_Cheat.get(1, new ItemStack(Blocks.iron_block, 1)); + } + + @Override + public Item getTabIconItem() { + return ItemList.Circuit_Integrated.getItem(); + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java new file mode 100644 index 0000000000..a2134290cf --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_FoodStat.java @@ -0,0 +1,102 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.F; +import gregtech.api.damagesources.GT_DamageSources; +import gregtech.api.interfaces.IFoodStat; +import gregtech.api.items.GT_MetaBase_Item; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.item.EnumAction; +import net.minecraft.item.ItemStack; +import net.minecraft.potion.PotionEffect; + +public class GT_FoodStat implements IFoodStat { + private final int mFoodLevel; + private final int[] mPotionEffects; + private final float mSaturation; + private final EnumAction mAction; + private final ItemStack mEmptyContainer; + private final boolean mAlwaysEdible, mInvisibleParticles, mIsRotten; + private boolean mExplosive = F, mMilk = F; + + /** + * @param aFoodLevel Amount of Food in Half Bacon [0 - 20] + * @param aSaturation Amount of Saturation [0.0F - 1.0F] + * @param aAction The Action to be used. If this is null, it uses the Eating Action + * @param aEmptyContainer An empty Container (Optional) + * @param aAlwaysEdible If this Item is always edible, like Golden Apples or Potions + * @param aInvisibleParticles If the Particles of the Potion Effects are invisible + * @param aPotionEffects An Array of Potion Effects with %4==0 Elements as follows + * ID of a Potion Effect. 0 for none + * Duration of the Potion in Ticks + * Level of the Effect. [0, 1, 2] are for [I, II, III] + * The likelihood that this Potion Effect takes place upon being eaten [1 - 100] + */ + public GT_FoodStat(int aFoodLevel, float aSaturation, EnumAction aAction, ItemStack aEmptyContainer, boolean aAlwaysEdible, boolean aInvisibleParticles, boolean aIsRotten, int... aPotionEffects) { + mFoodLevel = aFoodLevel; + mSaturation = aSaturation; + mAction = aAction==null?EnumAction.eat:aAction; + mPotionEffects = aPotionEffects; + mEmptyContainer = GT_Utility.copy(aEmptyContainer); + mInvisibleParticles = aInvisibleParticles; + mAlwaysEdible = aAlwaysEdible; + mIsRotten = aIsRotten; + } + + public GT_FoodStat setExplosive() { + mExplosive = true; + return this; + } + + public GT_FoodStat setMilk() { + mMilk = true; + return this; + } + + @Override + public int getFoodLevel(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { + return mFoodLevel; + } + + @Override + public float getSaturation(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { + return mSaturation; + } + + @Override + public void onEaten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { + aStack.stackSize--; + ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer)); + if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack)) aPlayer.dropPlayerItemWithRandomChoice(tStack, true); + aPlayer.worldObj.playSoundAtEntity(aPlayer, "random.burp", 0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F); + if (!aPlayer.worldObj.isRemote) { + if (mMilk) { + aPlayer.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0)); + } + for (int i = 3; i < mPotionEffects.length; i+=4) { + if (aPlayer.worldObj.rand.nextInt(100) < mPotionEffects[i]) { + aPlayer.addPotionEffect(new PotionEffect(mPotionEffects[i-3], mPotionEffects[i-2], mPotionEffects[i-1], mInvisibleParticles)); + } + } + if (mExplosive) { + aPlayer.worldObj.newExplosion(aPlayer, aPlayer.posX, aPlayer.posY, aPlayer.posZ, 4, true, true); + aPlayer.attackEntityFrom(GT_DamageSources.getExplodingDamage(), Float.MAX_VALUE); + } + } + } + + @Override + public EnumAction getFoodAction(GT_MetaBase_Item aItem, ItemStack aStack) { + return mAction; + } + + @Override + public boolean alwaysEdible(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { + return mAlwaysEdible; + } + + @Override + public boolean isRotten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) { + return mIsRotten; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java b/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java new file mode 100644 index 0000000000..8511f76c49 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_IBoxableWrapper.java @@ -0,0 +1,12 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.T; +import ic2.api.item.IBoxable; +import net.minecraft.item.ItemStack; + +public class GT_IBoxableWrapper implements IBoxable { + @Override + public boolean canBeStoredInToolbox(ItemStack itemstack) { + return T; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java b/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java new file mode 100644 index 0000000000..0c15970429 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ItsNotMyFaultException.java @@ -0,0 +1,16 @@ +package gregtech.api.util; + +public class GT_ItsNotMyFaultException extends RuntimeException { + private static final long serialVersionUID = -8752778866486460495L; + + private String mError; + + public GT_ItsNotMyFaultException(String aError) { + mError = aError; + } + + @Override + public String toString() { + return "The GregTech-Addon has a Problem.\nIT'S NOT MY FAULT!!! Below is how to fix it.\n" + mError + "\nDO NOT COME TO ME WITH THIS CRASH. YOU CAUSED IT YOURSELF, AND I TOLD YOU HOW TO FIX IT!!!"; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_LanguageManager.java b/src/main/java/gregtech/api/util/GT_LanguageManager.java new file mode 100644 index 0000000000..b419b7100f --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_LanguageManager.java @@ -0,0 +1,95 @@ +package gregtech.api.util; + +import static gregtech.api.enums.GT_Values.E; +import gregtech.api.GregTech_API; + +import java.util.HashMap; +import java.util.Map.Entry; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; +import cpw.mods.fml.common.registry.LanguageRegistry; + +public class GT_LanguageManager { + public static Configuration sEnglishFile; + + public static final HashMap TEMPMAP = new HashMap(), BUFFERMAP = new HashMap(); + + public static String addStringLocalization(String aKey, String aEnglish) { + return addStringLocalization(aKey, aEnglish, true); + } + + public static String addStringLocalization(String aKey, String aEnglish, boolean aWriteIntoLangFile) { + if (aKey == null) return E; + if (aWriteIntoLangFile) aEnglish = writeToLangFile(aKey, aEnglish); + TEMPMAP.put(aKey.trim(), aEnglish); + LanguageRegistry.instance().injectLanguage("en_US", TEMPMAP); + TEMPMAP.clear(); + return aEnglish; + } + + private static synchronized String writeToLangFile(String aKey, String aEnglish) { + if (aKey == null) return E; + if (sEnglishFile == null) { + BUFFERMAP.put(aKey.trim(), aEnglish); + } else { + if (!BUFFERMAP.isEmpty()) { + for (Entry tEntry : BUFFERMAP.entrySet()) { + Property tProperty = sEnglishFile.get("LanguageFile", tEntry.getKey(), tEntry.getValue()); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sEnglishFile.save(); + } + BUFFERMAP.clear(); + } + Property tProperty = sEnglishFile.get("LanguageFile", aKey.trim(), aEnglish); + if (!tProperty.wasRead() && GregTech_API.sPostloadFinished) sEnglishFile.save(); + if (sEnglishFile.get("EnableLangFile", "UseThisFileAsLanguageFile", false).getBoolean(false)) aEnglish = tProperty.getString(); + } + return aEnglish; + } + + public static String getTranslation(String aKey) { + if (aKey == null) return E; + String tTrimmedKey = aKey.trim(), rTranslation = LanguageRegistry.instance().getStringLocalization(tTrimmedKey); + if (GT_Utility.isStringInvalid(rTranslation)) { + rTranslation = StatCollector.translateToLocal(tTrimmedKey); + if (GT_Utility.isStringInvalid(rTranslation) || tTrimmedKey.equals(rTranslation)) { + if (aKey.endsWith(".name")) { + rTranslation = StatCollector.translateToLocal(tTrimmedKey.substring(0, tTrimmedKey.length() - 5)); + if (GT_Utility.isStringInvalid(rTranslation) || tTrimmedKey.substring(0, tTrimmedKey.length() - 5).equals(rTranslation)) { + return aKey; + } + } else { + rTranslation = StatCollector.translateToLocal(tTrimmedKey + ".name"); + if (GT_Utility.isStringInvalid(rTranslation) || (tTrimmedKey + ".name").equals(rTranslation)) { + return aKey; + } + } + } + } + return rTranslation; + } + + public static String getTranslation(String aKey, String aSeperator) { + if (aKey == null) return E; + String rTranslation = E; + for (String tString : aKey.split(aSeperator)) { + rTranslation += getTranslation(tString); + } + return rTranslation; + } + + public static String getTranslateableItemStackName(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return "null"; + NBTTagCompound tNBT = aStack.getTagCompound(); + if (tNBT != null && tNBT.hasKey("display")) { + String tName = tNBT.getCompoundTag("display").getString("Name"); + if (GT_Utility.isStringValid(tName)) { + return tName; + } + } + return aStack.getUnlocalizedName() + ".name"; + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/util/GT_Log.java b/src/main/java/gregtech/api/util/GT_Log.java new file mode 100644 index 0000000000..06a009175c --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_Log.java @@ -0,0 +1,35 @@ +package gregtech.api.util; + +import java.io.File; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; + +/** + * NEVER INCLUDE THIS FILE IN YOUR MOD!!! + * + * Just a simple Logging Function. If on Server, then this will point to System.out and System.err + */ +public class GT_Log { + public static PrintStream out = System.out; + public static PrintStream err = System.err; + public static PrintStream ore = new LogBuffer(); + public static PrintStream pal = null; + public static File mLogFile; + public static File mOreDictLogFile; + public static File mPlayerActivityLogFile; + + public static class LogBuffer extends PrintStream { + public final List mBufferedOreDictLog = new ArrayList(); + + public LogBuffer() { + super(new OutputStream() {@Override public void write(int arg0) {/*Do nothing*/}}); + } + + @Override + public void println(String aString) { + mBufferedOreDictLog.add(aString); + } + } +} \ No newline at end of file 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..22759cd057 --- /dev/null +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -0,0 +1,1727 @@ +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 sIC2ItemMap = new HashMap(); + + /** + * 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 sExtractorRecipes = new HashMap(); + private static Map sMaceratorRecipes = new HashMap(); + private static Map sCompressorRecipes = new HashMap(); + private static Map sOreWashingRecipes = new HashMap(); + private static Map sThermalCentrifugeRecipes = new HashMap(); + private static Map sMassfabRecipes = new HashMap(); + + public static Map getExtractorRecipeList() { + try { + return ic2.api.recipe.Recipes.extractor.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sExtractorRecipes; + } + + public static Map getCompressorRecipeList() { + try { + return ic2.api.recipe.Recipes.compressor.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sCompressorRecipes; + } + + public static Map getMaceratorRecipeList() { + try { + return ic2.api.recipe.Recipes.macerator.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sMaceratorRecipes; + } + + public static Map getThermalCentrifugeRecipeList() { + try { + return ic2.api.recipe.Recipes.centrifuge.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sThermalCentrifugeRecipes; + } + + public static Map getOreWashingRecipeList() { + try { + return ic2.api.recipe.Recipes.oreWashing.getRecipes(); + } catch(Throwable e) {/*Do nothing*/} + return sOreWashingRecipes; + } + + public static Map 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 { +