package reborncore.common.powerSystem.tesla;

import net.darkhax.tesla.capability.TeslaStorage;
import net.darkhax.tesla.lib.TeslaUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import reborncore.common.RebornCoreConfig;
import reborncore.common.powerSystem.TilePowerAcceptor;

/**
 * Created by modmuss50 on 06/05/2016.
 */
public class TeslaPowerManager implements ITeslaPowerManager {

    AdvancedTeslaContainer container;

    @Override
    public void readFromNBT(NBTTagCompound compound, TilePowerAcceptor powerAcceptor) {
        this.container = new AdvancedTeslaContainer(compound.getTag("TeslaContainer"), powerAcceptor);
    }

    @Override
    public void writeToNBT(NBTTagCompound compound, TilePowerAcceptor powerAcceptor) {
        compound.setTag("TeslaContainer", this.container.writeNBT());
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing, TilePowerAcceptor powerAcceptor) {
        if (capability == TeslaStorage.TESLA_HANDLER_CAPABILITY)
            return (T) this.container;

        return null;
    }

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing, TilePowerAcceptor powerAcceptor) {
        if (capability == TeslaStorage.TESLA_HANDLER_CAPABILITY)
            return true;
        return false;
    }

    @Override
    public void update(TilePowerAcceptor powerAcceptor) {
        if(powerAcceptor.canProvideEnergy(null)){
            TeslaUtils.distributePowerEqually(powerAcceptor.getWorld(), powerAcceptor.getPos(), (long) powerAcceptor.getMaxOutput(), false);
        }
    }

    @Override
    public void created(TilePowerAcceptor powerAcceptor) {
        this.container = new AdvancedTeslaContainer(powerAcceptor);
    }

    @Override
    public String getDisplayableTeslaCount(long tesla) {
        return TeslaUtils.getDisplayableTeslaCount(tesla / RebornCoreConfig.euPerRF);
    }

    public static ITeslaPowerManager getPowerManager(){
        return new TeslaPowerManager();
    }
}

@@ -80,23 +80,28 @@
 ty.Tesla
-Storage
+Capabilities
 ;%0Aimport
@@ -1068,38 +1068,137 @@
 == Tesla
-Storage.TESLA_HANDLER_
+Capabilities.CAPABILITY_CONSUMER %7C%7C capability == TeslaCapabilities.CAPABILITY_HOLDER %7C%7C capability == TeslaCapabilities.
 CAPABILI
@@ -1191,32 +1191,41 @@
 ities.CAPABILITY
+_PRODUCER
 )%0A            re
@@ -1440,30 +1440,129 @@
 esla
-Storage.TESLA_HANDLER_
+Capabilities.CAPABILITY_CONSUMER %7C%7C capability == TeslaCapabilities.CAPABILITY_HOLDER %7C%7C capability == TeslaCapabilities.
 CAPA
@@ -1567,16 +1567,25 @@
 PABILITY
+_PRODUCER
 )%0A      
@@ -1714,16 +1714,17 @@
       if
+ 
 (powerAc
@@ -1753,16 +1753,17 @@
 y(null))
+ 
 %7B%0A      
@@ -2222,24 +2222,24 @@
 RF);%0A    %7D%0A%0A
-
     public s
@@ -2280,16 +2280,17 @@
 anager()
+ 
 %7B%0A      

Update tesla support