diff options
| author | Foghrye4 <foghrye4@gmail.com> | 2017-08-10 18:50:56 +0300 |
|---|---|---|
| committer | Foghrye4 <foghrye4@gmail.com> | 2017-08-10 18:50:56 +0300 |
| commit | 877312184c472d9845e5ef1008bc538f4634059f (patch) | |
| tree | 4e098cc94296cc11f3b87e8ef64c3c568b6aeb51 /main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java | |
| parent | 939d2ea16679ce64d98b98c716b85f851aa576e2 (diff) | |
fix missing source folder
Diffstat (limited to 'main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java')
| -rw-r--r-- | main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java b/main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java new file mode 100644 index 0000000..5bbd72c --- /dev/null +++ b/main/java/gregtech/api/interfaces/tileentity/IExperimentalEnergyTileEntity.java @@ -0,0 +1,79 @@ +package gregtech.api.interfaces.tileentity; + +import static gregtech.api.enums.GT_Values.F; +import static gregtech.api.enums.GT_Values.T; + +import gregtech.api.enums.SubTag; +import gregtech.api.util.GT_Utility; +import ic2.api.energy.tile.IEnergySink; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * THIS IS GOING TO BE USED IN 1.8 + * + * Interface for getting Connected to the GregTech Energy Network. + * + * This is all you need to connect to the GT Network. + * IColoredTileEntity is needed for not connecting differently coloured Blocks to each other. + * IHasWorldObjectAndCoords is needed for the InWorld related Stuff. @BaseTileEntity does implement most of that Interface. + */ +public interface IExperimentalEnergyTileEntity extends IColoredTileEntity, IHasWorldObjectAndCoords { + /** + * Inject Energy Call for Electricity. Gets called by EnergyEmitters to inject Energy into your Block + * + * Note: you have to check for @inputEnergyFrom because the Network won't check for that by itself. + * + * @param aSide 0 - 5 = Vanilla Directions of YOUR Block the Energy gets inserted to. 6 = No specific Side (don't do Side checks for this Side) + * @return amount of used Amperes. 0 if not accepted anything. + */ + public long injectEnergy(SubTag aEnergyType, byte aSide, long aPrimary, long aSecondary); + + /** Sided Energy Input */ + public boolean inputEnergyFrom(SubTag aEnergyType, byte aSide); + + /** Sided Energy Output */ + public boolean outputsEnergyTo(SubTag aEnergyType, byte aSide); + + /** Utility for the Network */ + public static class Util { + private static boolean RF_ENERGY = F, IC_ENERGY = F, CHECK_ALL = T; + public static int RF_PER_EU = 4; + + private static void checkAvailabilities() { + if (CHECK_ALL) { + try { + Class tClass = ic2.api.energy.tile.IEnergySink.class; + tClass.getCanonicalName(); + IC_ENERGY = T; + } catch(Throwable e) {/**/} + CHECK_ALL = F; + } + } + + /** + * Emits Energy to the adjacent Blocks. Also compatible with adjacent IC2 TileEntities when electric and RF TileEntities when RedstoneFlux. + * @return the amount of used secondary value. + */ + public static final long emitEnergyToNetwork(SubTag aEnergyType, long aPrimary, long aSecondary, IExperimentalEnergyTileEntity aEmitter) { + long rUsedSecondary = 0; + checkAvailabilities(); + for (byte i = 0, j = 0; i < 6 && aSecondary > rUsedSecondary; i++) if (aEmitter.outputsEnergyTo(aEnergyType, i)) { + j = GT_Utility.getOppositeSide(i); + TileEntity tTileEntity = aEmitter.getTileEntityAtSide(i); + if (tTileEntity instanceof IExperimentalEnergyTileEntity) { + if (aEmitter.getColorization() >= 0) { + byte tColor = ((IExperimentalEnergyTileEntity)tTileEntity).getColorization(); + if (tColor >= 0 && tColor != aEmitter.getColorization()) continue; + } + rUsedSecondary+=((IExperimentalEnergyTileEntity)tTileEntity).injectEnergy(aEnergyType, j, aPrimary, aSecondary-rUsedSecondary); + } else if (IC_ENERGY && aEnergyType == SubTag.ENERGY_ELECTRICITY && tTileEntity instanceof IEnergySink) { + if (((IEnergySink)tTileEntity).acceptsEnergyFrom((TileEntity)aEmitter, ForgeDirection.getOrientation(j))) { + while (aSecondary > rUsedSecondary && ((IEnergySink)tTileEntity).getDemandedEnergy() > 0 && ((IEnergySink)tTileEntity).injectEnergy(ForgeDirection.getOrientation(j), aPrimary, aPrimary) < aPrimary) rUsedSecondary++; + } + } + } + return rUsedSecondary; + } + } +}
\ No newline at end of file |
