diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
19 files changed, 6471 insertions, 5885 deletions
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java index fe1055c2c8..794b560166 100644 --- a/src/main/java/gregtech/api/util/GT_BaseCrop.java +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -1,6 +1,5 @@ package gregtech.api.util; -import static gregtech.api.enums.GT_Values.E; import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; import gregtech.api.enums.Materials; @@ -11,196 +10,193 @@ import gregtech.common.blocks.GT_TileEntity_Ores; 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.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import java.util.ArrayList; +import java.util.Random; + +import static gregtech.api.enums.GT_Values.E; + 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], mGrowthSpeed = 0; - private ItemStack mDrop = null, mSpecialDrops[] = null; - private Materials mBlock = null; - - - public static ArrayList<GT_BaseCrop> sCropList = new ArrayList<GT_BaseCrop>(); - - /** - * 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) { - new GT_BaseCrop( aID, aCropName, aDiscoveredBy, aDrop, aSpecialDrops, aBaseSeed, aTier, aMaxSize, aGrowthSpeed, aAfterHarvestSize, aHarvestSize, aStatChemical, aStatFood, aStatDefensive, aStatColor, aStatWeed, aAttributes, null); - } - - /** - * 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 - * @param aBlock the block below needed for crop to grow. If null no block needed - * @param aMeta meta of the block below(-1 if no meta) - */ - 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, Materials aBlock) { - 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); - 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; - mBlock = aBlock; - if (!Crops.instance.registerCrop(this, aID)) throw new GT_ItsNotMyFaultException("Make sure the Crop ID is valid!"); - if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, this, 1, 1, 1, 1); - sCropList.add(this); - } - } - - @Override - public byte getSizeAfterHarvest(ICropTile crop) { - return (byte)mAfterHarvestSize; - } - - @Override - public int growthDuration(ICropTile aCrop){ - if(mGrowthSpeed<200)return super.growthDuration(aCrop); - return tier() * mGrowthSpeed; - } - - public int getrootslength(ICropTile crop) { - return 3; - } - - @Override + public static ArrayList<GT_BaseCrop> sCropList = new ArrayList<GT_BaseCrop>(); + private String mName = E, mDiscoveredBy = "Gregorius Techneticies", mAttributes[]; + private int mTier = 0, mMaxSize = 0, mAfterHarvestSize = 0, mHarvestSize = 0, mStats[] = new int[5], mGrowthSpeed = 0; + private ItemStack mDrop = null, mSpecialDrops[] = null; + private Materials mBlock = null; + + /** + * 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) { + new GT_BaseCrop(aID, aCropName, aDiscoveredBy, aDrop, aSpecialDrops, aBaseSeed, aTier, aMaxSize, aGrowthSpeed, aAfterHarvestSize, aHarvestSize, aStatChemical, aStatFood, aStatDefensive, aStatColor, aStatWeed, aAttributes, null); + } + + /** + * 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 + * @param aBlock the block below needed for crop to grow. If null no block needed + * @param aMeta meta of the block below(-1 if no meta) + */ + 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, Materials aBlock) { + 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); + 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; + mBlock = aBlock; + if (!Crops.instance.registerCrop(this, aID)) + throw new GT_ItsNotMyFaultException("Make sure the Crop ID is valid!"); + if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, this, 1, 1, 1, 1); + sCropList.add(this); + } + } + + @Override + public byte getSizeAfterHarvest(ICropTile crop) { + return (byte) mAfterHarvestSize; + } + + @Override + public int growthDuration(ICropTile aCrop) { + if (mGrowthSpeed < 200) return super.growthDuration(aCrop); + return tier() * mGrowthSpeed; + } + + public int getrootslength(ICropTile crop) { + return 3; + } + + @Override public String[] attributes() { - return mAttributes; - } - - @Override - public String discoveredBy() { - return mDiscoveredBy; - } - - @Override + return mAttributes; + } + + @Override + public String discoveredBy() { + return mDiscoveredBy; + } + + @Override public final boolean canGrow(ICropTile aCrop) { - if(mBlock!=null&&aCrop.getSize()==mMaxSize-1){ - return isBlockBelow(aCrop); - } - return aCrop.getSize() < maxSize(); + if (mBlock != null && aCrop.getSize() == mMaxSize - 1) { + return isBlockBelow(aCrop); + } + return aCrop.getSize() < maxSize(); } - - @Override + + @Override public final boolean canBeHarvested(ICropTile aCrop) { return aCrop.getSize() >= mHarvestSize; } - - @Override - public boolean canCross(ICropTile aCrop) { - return aCrop.getSize() + 2 > maxSize(); - } - - @Override + + @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); - } - + 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(); - } - - public boolean isBlockBelow(ICropTile aCrop) - { - if (aCrop == null) { - return false; - } - for (int i = 1; i < this.getrootslength(aCrop); i++) - { - Block tBlock = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - if ((tBlock instanceof GT_Block_Ores)) - { - TileEntity tTileEntity = aCrop.getWorld().getTileEntity(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - if ((tTileEntity instanceof GT_TileEntity_Ores)) - { - Materials tMaterial = GregTech_API.sGeneratedMaterials[(((GT_TileEntity_Ores)tTileEntity).mMetaData % 1000)]; - if ((tMaterial != null) && (tMaterial != Materials._NULL)) - { - if(tMaterial==mBlock){return true;}else{return false;} - } - } - } - else - { - int tMetaID = aCrop.getWorld().getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore"))&&(tAssotiation.mMaterial.mMaterial==mBlock)) - { - return true; - } - if ((tAssotiation != null) && (tAssotiation.mPrefix==OrePrefixes.block)&&(tAssotiation.mMaterial.mMaterial==mBlock)) - { - return true; - } - } + if (!canBeHarvested(aCrop)) return false; + return aCrop.harvest(aPlayer == null ? false : aPlayer instanceof EntityPlayerMP); + } + + @Override + public int getOptimalHavestSize(ICropTile crop) { + return maxSize(); + } + + public boolean isBlockBelow(ICropTile aCrop) { + if (aCrop == null) { + return false; + } + for (int i = 1; i < this.getrootslength(aCrop); i++) { + Block tBlock = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + if ((tBlock instanceof GT_Block_Ores)) { + TileEntity tTileEntity = aCrop.getWorld().getTileEntity(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + if ((tTileEntity instanceof GT_TileEntity_Ores)) { + Materials tMaterial = GregTech_API.sGeneratedMaterials[(((GT_TileEntity_Ores) tTileEntity).mMetaData % 1000)]; + if ((tMaterial != null) && (tMaterial != Materials._NULL)) { + if (tMaterial == mBlock) { + return true; + } else { + return false; + } + } + } + } else { + int tMetaID = aCrop.getWorld().getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); + ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); + if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore")) && (tAssotiation.mMaterial.mMaterial == mBlock)) { + return true; + } + if ((tAssotiation != null) && (tAssotiation.mPrefix == OrePrefixes.block) && (tAssotiation.mMaterial.mMaterial == mBlock)) { + return true; + } + } // Block block = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); // if (block.isAir(aCrop.getWorld(), aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ)) { // return false; @@ -210,8 +206,8 @@ public class GT_BaseCrop extends CropCard { // if(mMeta < 0 || tMeta == mMeta){ // return true;} // } - } - return false; - } - + } + return false; + } + } diff --git a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java index 6cda3c202f..4adf7e0f26 100644 --- a/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java +++ b/src/main/java/gregtech/api/util/GT_CircuitryBehavior.java @@ -1,178 +1,181 @@ 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; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IRedstoneCircuitBlock; /** * Redstone Circuit Control Code - * + * <p/> * 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. - * + * <p/> * 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. - * + * <p/> * 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; - } + /** + * @param aIndex 0 - 1023 are my own Indices, so use other Numbers! + */ + public GT_CircuitryBehavior(int aIndex) { + GregTech_API.sCircuitryBehaviors.put(aIndex, this); + } + + /** + * 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; + } + + /***************** + * GUI Functions * + *****************/ + + /** + * 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; + } + + /** + * 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); + + + /**************************** + * Useful Utility Functions * + ****************************/ + + /** + * 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); + + /** + * 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; + } }
\ 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 index 3ba9603114..f4631f5de6 100644 --- a/src/main/java/gregtech/api/util/GT_Config.java +++ b/src/main/java/gregtech/api/util/GT_Config.java @@ -1,85 +1,87 @@ package gregtech.api.util; -import static gregtech.api.enums.GT_Values.E; import gregtech.api.GregTech_API; import net.minecraft.item.ItemStack; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import static gregtech.api.enums.GT_Values.E; + public class GT_Config implements Runnable { - public static boolean troll = false; - - 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 |
