package reborncore.common.powerSystem.mixin;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import reborncore.api.power.IEnergyInterfaceItem;
import reborncore.mixin.api.Inject;
import reborncore.mixin.api.Mixin;

@Mixin(target = "")
public abstract class BasePowerMixin implements IEnergyInterfaceItem {

	@Inject
	@Override
	public double getEnergy(ItemStack stack) {
		NBTTagCompound tagCompound = getOrCreateNbtData(stack);
		if (tagCompound.hasKey("charge")) {
			return tagCompound.getDouble("charge");
		}
		return 0;
	}

	@Inject
	@Override
	public void setEnergy(double energy, ItemStack stack) {
		NBTTagCompound tagCompound = getOrCreateNbtData(stack);
		tagCompound.setDouble("charge", energy);

		if (this.getEnergy(stack) > getMaxPower(stack)) {
			this.setEnergy(getMaxPower(stack), stack);
		} else if (this.getEnergy(stack) < 0) {
			this.setEnergy(0, stack);
		}
	}

	@Inject
	@Override
	public double addEnergy(double energy, ItemStack stack) {
		return addEnergy(energy, false, stack);
	}

	@Inject
	@Override
	public double addEnergy(double energy, boolean simulate, ItemStack stack) {
		double energyReceived = Math.min(getMaxPower(stack) - energy, Math.min(this.getMaxPower(stack), energy));

		if (!simulate) {
			setEnergy(energy + energyReceived, stack);
		}
		return energyReceived;
	}

	@Inject
	@Override
	public boolean canUseEnergy(double input, ItemStack stack) {
		return input <= getEnergy(stack);
	}

	@Inject
	@Override
	public double useEnergy(double energy, ItemStack stack) {
		return useEnergy(energy, false, stack);
	}

	@Inject
	@Override
	public double useEnergy(double extract, boolean simulate, ItemStack stack) {
		double energyExtracted = Math.min(extract, Math.min(this.getMaxTransfer(stack), extract));

		if (!simulate) {
			setEnergy(getEnergy(stack) - energyExtracted, stack);
		}
		return energyExtracted;
	}

	@Inject
	@Override
	public boolean canAddEnergy(double energy, ItemStack stack) {
		return this.getEnergy(stack) + energy <= getMaxPower(stack);
	}

	@Inject
	public NBTTagCompound getOrCreateNbtData(ItemStack itemStack) {
		NBTTagCompound tagCompound = itemStack.getTagCompound();
		if (tagCompound == null) {
			tagCompound = new NBTTagCompound();
			itemStack.setTagCompound(tagCompound);
		}

		return tagCompound;
	}

}

@@ -167,16 +167,116 @@
 ceItem;%0A
+import reborncore.common.powerSystem.PowerSystem;%0Aimport reborncore.common.powerSystem.PoweredItem;%0A
 import r
@@ -2412,10 +2412,372 @@
 nd;%0A%09%7D%0A%0A
+%09@Inject%0A%09public double getDurabilityForDisplay(ItemStack stack) %7B%0A%09%09double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));%0A%09%09return 1 - charge;%0A%09%7D%0A%0A%09@Inject%0A%09public boolean showDurabilityBar(ItemStack stack) %7B%0A%09%09return true;%0A%09%7D%0A%0A%09@Inject%0A%09public int getRGBDurabilityForDisplay(ItemStack stack) %7B%0A%09%09return PowerSystem.getDisplayPower().colour;%0A%09%7D%0A%0A
 %7D%0A

Add item power bar to the mixin