package reborncore.common.powerSystem.tesla;

import net.darkhax.tesla.api.ITeslaConsumer;
import net.darkhax.tesla.api.ITeslaHolder;
import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import reborncore.common.RebornCoreConfig;
import reborncore.common.powerSystem.TilePowerAcceptor;

/**
 * Created by modmuss50 on 06/05/2016.
 */
public class AdvancedTeslaContainer implements ITeslaConsumer, ITeslaHolder, ITeslaProducer {

	public TilePowerAcceptor tile;

	public AdvancedTeslaContainer(TilePowerAcceptor tile) {
		this.tile = tile;
	}

	public AdvancedTeslaContainer(NBTBase nbt, TilePowerAcceptor tile) {
		this.tile = tile;
		this.readNBT(nbt);
	}

	public long getStoredPower() {
		return (long) tile.getEnergy() * RebornCoreConfig.euPerFU;
	}

	//Receive
	public long givePower(long tesla, boolean simulated) {
		return (long) tile.addEnergy(tesla * RebornCoreConfig.euPerFU);
	}

	//Take power out
	public long takePower(long tesla, boolean simulated) {
		return (int) tile.useEnergy(tesla * RebornCoreConfig.euPerFU);
	}

	public long getCapacity() {
		return (long) tile.getMaxPower() * RebornCoreConfig.euPerFU;
	}

	public long getInputRate() {
		return (long) tile.getMaxInput() * RebornCoreConfig.euPerFU;
	}

	public long getOutputRate() {
		return (long) tile.getMaxOutput() * RebornCoreConfig.euPerFU;
	}

	public NBTBase writeNBT() {
		NBTTagCompound dataTag = new NBTTagCompound();
		return dataTag;
	}

	public void readNBT(NBTBase nbt) {
	}

	public boolean isInputSide() {
		return true;
	}

	public boolean isOutputSide() {
		return true;
	}

}

@@ -888,214 +888,522 @@
 %7B%0A%09%09
-return (long) tile.addEnergy(tesla * RebornCoreConfig.euPerFU);%0A%09%7D%0A%0A%09//Take power out%0A%09public long takePower(long tesla, boolean simulated) %7B%0A%09%09return (int) tile.useEnergy(tesla * RebornCoreConfig.euPerFU);
+double euToAdd = tesla * RebornCoreConfig.euPerFU;%0A%0A%09%09if (tile.canAddEnergy(euToAdd)) %7B%0A%09%09%09double euAdded = tile.addEnergy(euToAdd);%0A%09%09%09return (long) (euAdded / RebornCoreConfig.euPerFU);%0A%09%09%7D else %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%7D%0A%0A%09//Take power out%0A%09public long takePower(long tesla, boolean simulated) %7B%0A%09%09double euToTake = tesla * RebornCoreConfig.euPerFU;%0A%0A%09%09if (tile.canUseEnergy(euToTake)) %7B%0A%09%09%09double euTaken = tile.useEnergy(euToTake);%0A%09%09%09return (long) (euTaken / RebornCoreConfig.euPerFU);%0A%09%09%7D else %7B%0A%09%09%09return 0;%0A%09%09%7D
 %0A%09%7D%0A

Make givePower/takePower check for canAddEnergy/canUseEnergy