Search in sources :

Example 1 with IEnergizedItem

use of mekanism.api.energy.IEnergizedItem in project Galacticraft by micdoodle8.

the class TileBaseUniversalElectricalSource method recharge.

/**
 * Recharges electric item.
 */
public void recharge(ItemStack itemStack) {
    if (itemStack != null && itemStack.stackSize == 1) {
        Item item = itemStack.getItem();
        float maxExtractSave = this.storage.getMaxExtract();
        if (this.tierGC > 1) {
            this.storage.setMaxExtract(maxExtractSave * 2.5F);
        }
        float energyToCharge = this.storage.extractEnergyGC(this.storage.getMaxExtract(), true);
        if (item instanceof IItemElectric) {
            this.storage.extractEnergyGC(ElectricItemHelper.chargeItem(itemStack, energyToCharge), false);
        } else // }
        if (EnergyConfigHandler.isMekanismLoaded() && item instanceof IEnergizedItem && ((IEnergizedItem) item).canReceive(itemStack)) {
            this.storage.extractEnergyGC((float) EnergizedItemManager.charge(itemStack, energyToCharge * EnergyConfigHandler.TO_MEKANISM_RATIO) / EnergyConfigHandler.TO_MEKANISM_RATIO, false);
        } else if (EnergyConfigHandler.isIndustrialCraft2Loaded()) {
            if (item instanceof ISpecialElectricItem) {
                ISpecialElectricItem specialElectricItem = (ISpecialElectricItem) item;
                IElectricItemManager manager = specialElectricItem.getManager(itemStack);
                double result = manager.charge(itemStack, (double) (energyToCharge * EnergyConfigHandler.TO_IC2_RATIO), this.tierGC + 1, false, false);
                float energy = (float) result / EnergyConfigHandler.TO_IC2_RATIO;
                this.storage.extractEnergyGC(energy, false);
            } else if (item instanceof IElectricItem) {
                double result = ElectricItem.manager.charge(itemStack, (double) (energyToCharge * EnergyConfigHandler.TO_IC2_RATIO), this.tierGC + 1, false, false);
                float energy = (float) result / EnergyConfigHandler.TO_IC2_RATIO;
                this.storage.extractEnergyGC(energy, false);
            }
        }
        if (this.tierGC > 1) {
            this.storage.setMaxExtract(maxExtractSave);
        }
    }
}
Also used : Item(net.minecraft.item.Item) ElectricItem(ic2.api.item.ElectricItem) ISpecialElectricItem(ic2.api.item.ISpecialElectricItem) IElectricItem(ic2.api.item.IElectricItem) IEnergizedItem(mekanism.api.energy.IEnergizedItem) IItemElectric(micdoodle8.mods.galacticraft.api.item.IItemElectric) ISpecialElectricItem(ic2.api.item.ISpecialElectricItem) IElectricItem(ic2.api.item.IElectricItem) IEnergizedItem(mekanism.api.energy.IEnergizedItem) IElectricItemManager(ic2.api.item.IElectricItemManager)

Example 2 with IEnergizedItem

use of mekanism.api.energy.IEnergizedItem in project Galacticraft by micdoodle8.

the class TileBaseUniversalElectrical method discharge.

public void discharge(ItemStack itemStack) {
    if (itemStack != null) {
        Item item = itemStack.getItem();
        float energyToDischarge = this.getRequest(null);
        if (item instanceof IItemElectric) {
            this.storage.receiveEnergyGC(ElectricItemHelper.dischargeItem(itemStack, energyToDischarge));
        } else // }
        if (EnergyConfigHandler.isMekanismLoaded() && item instanceof IEnergizedItem && ((IEnergizedItem) item).canSend(itemStack)) {
            this.storage.receiveEnergyGC((float) EnergizedItemManager.discharge(itemStack, energyToDischarge / EnergyConfigHandler.MEKANISM_RATIO) * EnergyConfigHandler.MEKANISM_RATIO);
        } else if (EnergyConfigHandler.isIndustrialCraft2Loaded()) {
            if (item instanceof ISpecialElectricItem) {
                ISpecialElectricItem electricItem = (ISpecialElectricItem) item;
                if (electricItem.canProvideEnergy(itemStack)) {
                    double energyDischargeIC2 = energyToDischarge / EnergyConfigHandler.IC2_RATIO;
                    double result = electricItem.getManager(itemStack).discharge(itemStack, energyDischargeIC2, 4, false, false, false);
                    float energyDischarged = (float) result * EnergyConfigHandler.IC2_RATIO;
                    this.storage.receiveEnergyGC(energyDischarged);
                }
            } else if (item instanceof IElectricItem) {
                IElectricItem electricItem = (IElectricItem) item;
                if (electricItem.canProvideEnergy(itemStack)) {
                    double energyDischargeIC2 = energyToDischarge / EnergyConfigHandler.IC2_RATIO;
                    double result = ElectricItem.manager.discharge(itemStack, energyDischargeIC2, 4, false, false, false);
                    float energyDischarged = (float) result * EnergyConfigHandler.IC2_RATIO;
                    this.storage.receiveEnergyGC(energyDischarged);
                }
            }
        }
    // else if (GCCoreCompatibilityManager.isTELoaded() && itemStack.getItem() instanceof IEnergyContainerItem)
    // {
    // float given = ((IEnergyContainerItem) itemStack.getItem()).extractEnergy(itemStack, (int) Math.floor(this.getRequest(EnumFacing.UNKNOWN) * EnergyConfigHandler.TO_TE_RATIO), false);
    // this.receiveElectricity(given * EnergyConfigHandler.TE_RATIO, true);
    // }
    }
}
Also used : Item(net.minecraft.item.Item) ISpecialElectricItem(ic2.api.item.ISpecialElectricItem) ElectricItem(ic2.api.item.ElectricItem) IElectricItem(ic2.api.item.IElectricItem) IEnergizedItem(mekanism.api.energy.IEnergizedItem) IItemElectric(micdoodle8.mods.galacticraft.api.item.IItemElectric) ISpecialElectricItem(ic2.api.item.ISpecialElectricItem) IElectricItem(ic2.api.item.IElectricItem) IEnergizedItem(mekanism.api.energy.IEnergizedItem)

Aggregations

ElectricItem (ic2.api.item.ElectricItem)2 IElectricItem (ic2.api.item.IElectricItem)2 ISpecialElectricItem (ic2.api.item.ISpecialElectricItem)2 IEnergizedItem (mekanism.api.energy.IEnergizedItem)2 IItemElectric (micdoodle8.mods.galacticraft.api.item.IItemElectric)2 Item (net.minecraft.item.Item)2 IElectricItemManager (ic2.api.item.IElectricItemManager)1