diff --git a/src/main/java/gregtech/api/capability/ICoverable.java b/src/main/java/gregtech/api/capability/ICoverable.java index dd4185c0..bb4eec15 100644 --- a/src/main/java/gregtech/api/capability/ICoverable.java +++ b/src/main/java/gregtech/api/capability/ICoverable.java @@ -1,25 +1,22 @@ package gregtech.api.capability; -import gregtech.api.capability.internal.IRedstoneTileEntity; import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; -public interface ICoverable extends IRedstoneTileEntity { +public interface ICoverable { - /** - * If a Cover of that Type can be placed on this Side. - */ - boolean allowCoverOnSide(EnumFacing side, int coverId); + @CapabilityInject(ICoverable.class) + public static final Capability CAPABILITY_COVERABLE = null; - boolean dropCover(EnumFacing side, EnumFacing droppedSide, boolean forced); + boolean allowCoverOnSide(int coverId); - void setCoverDataAtSide(EnumFacing side, int coverData); + boolean dropCover(EnumFacing droppedSide, boolean forced); - void setCoverIDAtSide(EnumFacing side, int coverId); + void setCoverIDAtSide(int coverId); - int getCoverDataAtSide(EnumFacing side); + int getCoverID(); - int getCoverIDAtSide(EnumFacing side); - - void setCoverRedstoneOutput(EnumFacing side, byte strength); + void setCoverRedstoneOutput(byte strength); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/capability/IEnergyConnected.java b/src/main/java/gregtech/api/capability/IEnergyConnected.java deleted file mode 100644 index b4bfa772..00000000 --- a/src/main/java/gregtech/api/capability/IEnergyConnected.java +++ /dev/null @@ -1,84 +0,0 @@ -package gregtech.api.capability; - -import cofh.api.energy.IEnergyReceiver; -import gregtech.api.GregTech_API; -import gregtech.api.capability.internal.IHasWorldObjectAndCoords; -import ic2.api.energy.tile.IEnergyAcceptor; -import ic2.api.energy.tile.IEnergyEmitter; -import ic2.api.energy.tile.IEnergySink; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; - -/** - * Interface for getting Connected to the GregTech Energy Network. - *

- * This is all you need to connect to the GT Network. - * IPaintable is needed for not connecting differently coloured Blocks to each other. - * IHasWorldObjectAndCoords is needed for the InWorld related Stuff. @TickableTileEntityBase does implement most of that Interface. - */ -public interface IEnergyConnected extends IPaintable, IHasWorldObjectAndCoords, IEnergyAcceptor, IEnergyEmitter { - - /** - * 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 side 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. - */ - long injectEnergyUnits(EnumFacing side, long voltage, long amperage); - - /** - * Sided Energy Input - */ - boolean inputEnergyFrom(EnumFacing side); - - /** - * Sided Energy Output - */ - boolean outputsEnergyTo(EnumFacing side); - - /** - * Utility for the Network - */ - class Util { - - /** - * Emits Energy to the E-net. Also compatible with adjacent IC2 TileEntities. - * - * @return the used Amperage. - */ - - public static long emitEnergyToNetwork(long voltage, long amperage, IEnergyConnected emitter) { - long rUsedAmperes = 0; - for (EnumFacing side : EnumFacing.VALUES) { - if (amperage <= rUsedAmperes) break; - EnumFacing oppositeSide = side.getOpposite(); - if (emitter.outputsEnergyTo(side)) { - TileEntity tileEntity = emitter.getWorldObj().getTileEntity(emitter.getWorldPos().offset(side)); - if (tileEntity instanceof IEnergyConnected) { - if (emitter.getColorization() >= 0) { - byte tColor = ((IEnergyConnected) tileEntity).getColorization(); - if (tColor >= 0 && tColor != emitter.getColorization()) continue; - } - rUsedAmperes += ((IEnergyConnected) tileEntity).injectEnergyUnits(oppositeSide, voltage, amperage - rUsedAmperes); - } else if (tileEntity instanceof IEnergySink) { - if (((IEnergySink) tileEntity).acceptsEnergyFrom(emitter, oppositeSide)) { - while (amperage > rUsedAmperes && ((IEnergySink) tileEntity).getDemandedEnergy() > 0 && - ((IEnergySink) tileEntity).injectEnergy(oppositeSide, voltage, voltage) < voltage) - rUsedAmperes++; - } - } else if (tileEntity instanceof IEnergyReceiver) { - int rfOut = (int) (voltage * GregTech_API.mEUtoRF / 100); - if (((IEnergyReceiver) tileEntity).receiveEnergy(oppositeSide, rfOut, true) == rfOut) { - ((IEnergyReceiver) tileEntity).receiveEnergy(oppositeSide, rfOut, false); - rUsedAmperes++; - } - } - } - } - return rUsedAmperes; - } - } - -} \ No newline at end of file diff --git a/src/main/java/gregtech/api/capability/IBasicEnergyContainer.java b/src/main/java/gregtech/api/capability/IEnergyContainer.java similarity index 79% rename from src/main/java/gregtech/api/capability/IBasicEnergyContainer.java rename to src/main/java/gregtech/api/capability/IEnergyContainer.java index 3c7027e2..fb9c4c26 100644 --- a/src/main/java/gregtech/api/capability/IBasicEnergyContainer.java +++ b/src/main/java/gregtech/api/capability/IEnergyContainer.java @@ -1,6 +1,22 @@ package gregtech.api.capability; -public interface IBasicEnergyContainer extends IEnergyConnected { +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.CapabilityInject; + +public interface IEnergyContainer { + + @CapabilityInject(IEnergyContainer.class) + public static final Capability CAPABILITY_ENERGY_CONTAINER = null; + + /** + * @return amount of used amperes. 0 if not accepted anything. + */ + long acceptEnergyFromNetwork(long voltage, long amperage); + + boolean inputsEnergy(); + + boolean outputsEnergy(); + /** * Gets if that amount of electric energy is stored inside the machine. diff --git a/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java b/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java index 2cf38da5..14d556b7 100644 --- a/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java +++ b/src/main/java/gregtech/api/capability/SimpleCapabilityManager.java @@ -29,6 +29,12 @@ public class SimpleCapabilityManager { public static void init() { registerCapability(ITurnable.class); + registerCapability(IPaintable.class); + registerCapability(IDescribable.class); + registerCapability(IEnergyContainer.class); + registerCapability(IWorkable.class); + registerCapability(IUpgradable.class); + registerCapability(ICoverable.class); } } diff --git a/src/main/java/gregtech/api/capability/internal/IHasWorldObjectAndCoords.java b/src/main/java/gregtech/api/capability/internal/IHasWorldObjectAndCoords.java index 569201e0..3c7be124 100644 --- a/src/main/java/gregtech/api/capability/internal/IHasWorldObjectAndCoords.java +++ b/src/main/java/gregtech/api/capability/internal/IHasWorldObjectAndCoords.java @@ -1,16 +1,7 @@ package gregtech.api.capability.internal; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.fluids.IFluidHandler; public interface IHasWorldObjectAndCoords { diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 183e47f6..9bacaba0 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1190,10 +1190,10 @@ public class GT_Utility { if (tString != null && !tString.equals(E)) tList.add(tString); } - if (tTileEntity instanceof IBasicEnergyContainer && ((IBasicEnergyContainer) tTileEntity).getEUCapacity() > 0) { - tList.add("Max IN: " + ((IBasicEnergyContainer) tTileEntity).getInputVoltage() + " EU"); - tList.add("Max OUT: " + ((IBasicEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IBasicEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes"); - tList.add("Energy: " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IBasicEnergyContainer) tTileEntity).getEUCapacity()) + "EU"); + if (tTileEntity instanceof IEnergyContainer && ((IEnergyContainer) tTileEntity).getEUCapacity() > 0) { + tList.add("Max IN: " + ((IEnergyContainer) tTileEntity).getInputVoltage() + " EU"); + tList.add("Max OUT: " + ((IEnergyContainer) tTileEntity).getOutputVoltage() + " EU at " + ((IEnergyContainer) tTileEntity).getOutputAmperage() + " Amperes"); + tList.add("Energy: " + GT_Utility.formatNumbers(((IEnergyContainer) tTileEntity).getStoredEU()) + " / " + GT_Utility.formatNumbers(((IEnergyContainer) tTileEntity).getEUCapacity()) + "EU"); } if (tTileEntity instanceof IGregTechTileEntity) {