package de.nedelosk.modularmachines.common.plugins.cofh;

import cofh.api.energy.EnergyStorage;
import de.nedelosk.modularmachines.api.energy.EnergyRegistry;
import de.nedelosk.modularmachines.api.energy.IEnergyType;
import de.nedelosk.modularmachines.api.modules.IModule;
import de.nedelosk.modularmachines.api.modules.handlers.energy.IModuleEnergyInterface;
import de.nedelosk.modularmachines.api.modules.state.IModuleState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;

public class ModuleRFInterface<M extends IModule> implements IModuleEnergyInterface {

	protected final IModuleState<M> state;
	protected final EnergyStorage storage;

	public ModuleRFInterface(IModuleState<M> state, EnergyStorage storage) {
		this.state = state;
		this.storage = storage;
	}

	@Override
	public IModuleState getModuleState() {
		return state;
	}

	@Override
	public String getUID() {
		return "EnergyInterface";
	}

	@Override
	public void readFromNBT(NBTTagCompound nbt) {
		storage.readFromNBT(nbt);
	}

	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
		storage.writeToNBT(nbt);
		return nbt;
	}

	@Override
	public long extractEnergy(IEnergyType energyType, long maxExtract, boolean simulate) {
		return storage.extractEnergy((int)maxExtract, simulate);
	}

	@Override
	public long receiveEnergy(IEnergyType energyType, long maxReceive, boolean simulate) {
		return storage.receiveEnergy((int)maxReceive, simulate);
	}

	@Override
	public long getEnergyStored(IEnergyType energyType) {
		return storage.getEnergyStored();
	}

	@Override
	public long getCapacity(IEnergyType energyType) {
		return storage.getMaxEnergyStored();
	}

	@Override
	public boolean canConnectEnergy(IEnergyType energyType) {
		return true;
	}

	@Override
	public boolean isInput(IEnergyType energyType) {
		return true;
	}

	@Override
	public boolean isOutput(IEnergyType energyType) {
		return true;
	}

	@Override
	public IEnergyType[] getValidTypes() {
		return new IEnergyType[]{EnergyRegistry.redstoneFlux};
	}

	@Override
	public EnumFacing getFacing() {
		return null;
	}
}

@@ -498,16 +498,72 @@
 mFacing;
+%0Aimport net.minecraftforge.common.util.INBTSerializable;
 %0A%0Apublic
@@ -639,16 +639,50 @@
 nterface
+, INBTSerializable%3CNBTTagCompound%3E
  %7B%0A%0A%09pro
@@ -1019,24 +1019,25 @@
 erface%22;%0A%09%7D%0A
+%09
 %0A%09@Override%0A
@@ -1049,24 +1049,27 @@
 ic void 
-readFrom
+deserialize
 NBT(NBTT
@@ -1113,24 +1113,25 @@
 BT(nbt);%0A%09%7D%0A
+%09
 %0A%09@Override%0A
@@ -1157,40 +1157,69 @@
 und 
-writeToNBT(NBTTagCompound nbt) %7B
+serializeNBT() %7B%0A%09%09NBTTagCompound nbt = new NBTTagCompound();
 %0A%09%09s

Fix rf interface