package lumaceon.mods.clockworkphase2.tile.generic;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.energy.IEnergyStorage;
public abstract class TileModInventoryEnergy extends TileModInventory implements IEnergyStorage
{
@CapabilityInject(IEnergyStorage.class)
static Capability<IEnergyStorage> ENERGY_STORAGE_CAPABILITY = null;
public IEnergyStorage energyStorage;
public TileModInventoryEnergy(int size, int stackLimit, int energyCapacity, int maxTransfer) {
super(size, stackLimit);
this.energyStorage = new EnergyStorage(energyCapacity, maxTransfer);
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return energyStorage.receiveEnergy(maxReceive, simulate);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return energyStorage.extractEnergy(maxExtract, simulate);
}
@Override
public int getEnergyStored() {
return energyStorage.getEnergyStored();
}
@Override
public int getMaxEnergyStored() {
return energyStorage.getMaxEnergyStored();
}
@Override
public boolean canExtract() {
return energyStorage.canExtract();
}
@Override
public boolean canReceive() {
return energyStorage.canReceive();
}
@Override
public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) {
return capability != null && capability == ENERGY_STORAGE_CAPABILITY || super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
{
if(hasCapability(capability, facing))
return ENERGY_STORAGE_CAPABILITY.cast(energyStorage);
return super.getCapability(capability, facing);
}
}