Search in sources :

Example 1 with IEnergyContainerItem

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;
}
Also used : ItemJetpack(tonius.simplyjetpacks.item.ItemPack.ItemJetpack) JetPlate(tonius.simplyjetpacks.item.meta.JetPlate) PackBase(tonius.simplyjetpacks.item.meta.PackBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ParticleType(tonius.simplyjetpacks.setup.ParticleType) ItemPack(tonius.simplyjetpacks.item.ItemPack) ItemStack(net.minecraft.item.ItemStack) IEnergyContainerItem(cofh.api.energy.IEnergyContainerItem)

Example 2 with IEnergyContainerItem

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);
                }
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) IEnergyContainerItem(cofh.api.energy.IEnergyContainerItem)

Example 3 with IEnergyContainerItem

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;
                    }
                }
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack) IEnergyContainerItem(cofh.api.energy.IEnergyContainerItem)

Aggregations

IEnergyContainerItem (cofh.api.energy.IEnergyContainerItem)3 ItemStack (net.minecraft.item.ItemStack)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ItemPack (tonius.simplyjetpacks.item.ItemPack)1 ItemJetpack (tonius.simplyjetpacks.item.ItemPack.ItemJetpack)1 JetPlate (tonius.simplyjetpacks.item.meta.JetPlate)1 PackBase (tonius.simplyjetpacks.item.meta.PackBase)1 ParticleType (tonius.simplyjetpacks.setup.ParticleType)1