use of cofh.api.energy.IEnergyContainerItem in project SimplyJetpacks by Tonius.
the class UpgradingRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
int addedEnergy = 0;
ParticleType particleType = null;
NBTTagCompound tags = null;
boolean enderiumUpgrade = false;
ItemStack slotStack;
for (int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
slotStack = inventoryCrafting.getStackInSlot(i);
if (slotStack != null && slotStack.getItem() != null) {
if (slotStack.getItem() instanceof ItemPack) {
tags = (NBTTagCompound) NBTHelper.getNBT(slotStack).copy();
}
if (slotStack.getItem() instanceof IEnergyContainerItem) {
addedEnergy += ((IEnergyContainerItem) slotStack.getItem()).getEnergyStored(slotStack);
} else if (slotStack.getItem() == ModItems.particleCustomizers) {
particleType = ParticleType.values()[slotStack.getItemDamage()];
} else if (ModItems.enderiumUpgrade != null && slotStack.getItem() == ModItems.enderiumUpgrade.getItem() && slotStack.getItemDamage() == ModItems.enderiumUpgrade.getItemDamage()) {
enderiumUpgrade = true;
}
}
}
ItemStack result = new ItemStack((Item) this.resultItem, 1, this.resultMeta);
if (tags != null) {
result.setTagCompound(tags);
}
NBTHelper.getNBT(result).setInteger("Energy", Math.min(addedEnergy, this.resultItem.getMaxEnergyStored(result)));
if (this.resultItem instanceof ItemJetpack && particleType != null) {
((ItemJetpack) this.resultItem).getPack(result).setParticleType(result, particleType);
}
if (enderiumUpgrade && this.resultItem instanceof ItemPack) {
PackBase pack = ((ItemPack) this.resultItem).getPack(result);
if (pack instanceof JetPlate) {
((JetPlate) pack).setEnderiumUpgrade(result, true);
}
}
return result;
}
use of cofh.api.energy.IEnergyContainerItem in project SimplyJetpacks by Tonius.
the class PackBase method chargeInventory.
protected void chargeInventory(EntityLivingBase user, ItemStack stack, ItemPack item) {
if (this.fuelType == FuelType.ENERGY) {
for (int i = 0; i <= 4; i++) {
ItemStack currentStack = user.getEquipmentInSlot(i);
if (currentStack != null && currentStack != stack && currentStack.getItem() instanceof IEnergyContainerItem) {
IEnergyContainerItem heldEnergyItem = (IEnergyContainerItem) currentStack.getItem();
if (this.usesFuel) {
int energyToAdd = Math.min(item.useFuel(stack, this.fuelPerTickOut, true), heldEnergyItem.receiveEnergy(currentStack, this.fuelPerTickOut, true));
item.useFuel(stack, energyToAdd, false);
heldEnergyItem.receiveEnergy(currentStack, energyToAdd, false);
} else {
heldEnergyItem.receiveEnergy(currentStack, this.fuelPerTickOut, false);
}
}
}
}
}
use of cofh.api.energy.IEnergyContainerItem in project PneumaticCraft by MineMaarten.
the class TileEntityAerialInterface method tickRF.
private void tickRF() {
if (getEnergyStored(null) > 0) {
InventoryPlayer inv = getPlayerInventory();
if (inv != null) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof IEnergyContainerItem) {
IEnergyContainerItem chargingItem = (IEnergyContainerItem) stack.getItem();
int energyLeft = getEnergyStored(null);
if (energyLeft > 0) {
getEnergy().extractEnergy(chargingItem.receiveEnergy(stack, energyLeft, false), false);
} else {
break;
}
}
}
}
}
}
Aggregations