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);
}
}
}
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);
// }
}
}
Aggregations