Search in sources :

Example 1 with Energy

use of ic2.core.block.comp.Energy in project compactsolars by cpw.

the class BasicSink method onInvalidate.

/**
	 * Forward for the TileEntity's invalidate(), used for destroying the energy net link.
	 * Both onInvalidate and onOnChunkUnload have to be used.
	 */
public void onInvalidate() {
    if (addedToEnet) {
        MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
        addedToEnet = false;
    }
}
Also used : EnergyTileUnloadEvent(ic2.api.energy.event.EnergyTileUnloadEvent)

Example 2 with Energy

use of ic2.core.block.comp.Energy in project compactsolars by cpw.

the class BasicSource method onInvalidate.

/**
	 * Forward for the TileEntity's invalidate(), used for destroying the energy net link.
	 * Both onInvalidate and onOnChunkUnload have to be used.
	 */
public void onInvalidate() {
    if (addedToEnet) {
        MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
        addedToEnet = false;
    }
}
Also used : EnergyTileUnloadEvent(ic2.api.energy.event.EnergyTileUnloadEvent)

Example 3 with Energy

use of ic2.core.block.comp.Energy in project Galacticraft by micdoodle8.

the class EnergyNetwork method doProduce.

/**
 * Complete the energy transfer. Called internally on server tick end.
 *
 * @return Amount of energy SENT to all acceptors
 */
private float doProduce() {
    float sent = 0.0F;
    if (!this.availableAcceptors.isEmpty()) {
        float energyNeeded = this.totalRequested;
        float energyAvailable = this.totalEnergy;
        float reducor = 1.0F;
        float energyStorageReducor = 1.0F;
        if (energyNeeded > energyAvailable) {
            // If not enough energy, try reducing what goes into energy storage (if any)
            energyNeeded -= this.totalStorageExcess;
            // If there's still not enough, put the minimum into energy storage (if any) and, anyhow, reduce everything proportionately
            if (energyNeeded > energyAvailable) {
                energyStorageReducor = 0F;
                reducor = energyAvailable / energyNeeded;
            } else {
                // Energyavailable exceeds the total needed but only if storage does not fill all in one go - this is a common situation
                energyStorageReducor = (energyAvailable - energyNeeded) / this.totalStorageExcess;
            }
        }
        float currentSending;
        float sentToAcceptor;
        int tierProduced = Math.min(this.producersTierGC, this.networkTierGC);
        Object debugTE = null;
        try {
            for (Object tileEntity : this.availableAcceptors) {
                debugTE = tileEntity;
                // Exit the loop if there is no energy left at all (should normally not happen, should be some even for the last acceptor)
                if (sent >= energyAvailable) {
                    break;
                }
                // The base case is to give each acceptor what it is requesting
                currentSending = this.energyRequests.get(tileEntity);
                // If it's an energy store, we may need to damp it down if energyStorageReducor is less than 1
                if (currentSending > EnergyNetwork.ENERGY_STORAGE_LEVEL) {
                    currentSending = EnergyNetwork.ENERGY_STORAGE_LEVEL + (currentSending - EnergyNetwork.ENERGY_STORAGE_LEVEL) * energyStorageReducor;
                }
                // Reduce everything proportionately if there is not enough energy for all needs
                currentSending *= reducor;
                if (currentSending > energyAvailable - sent) {
                    currentSending = energyAvailable - sent;
                }
                EnumFacing sideFrom = this.availableconnectedDirections.get(tileEntity);
                if (tileEntity instanceof IElectrical) {
                    sentToAcceptor = ((IElectrical) tileEntity).receiveElectricity(sideFrom, currentSending, tierProduced, true);
                } else if (isMekLoaded && tileEntity instanceof IStrictEnergyAcceptor) {
                    sentToAcceptor = (float) ((IStrictEnergyAcceptor) tileEntity).transferEnergyToAcceptor(sideFrom, currentSending * EnergyConfigHandler.TO_MEKANISM_RATIO) / EnergyConfigHandler.TO_MEKANISM_RATIO;
                } else if (isIC2Loaded && tileEntity instanceof IEnergySink) {
                    double energySendingIC2 = currentSending * EnergyConfigHandler.TO_IC2_RATIO;
                    if (energySendingIC2 >= 1D) {
                        double result = 0;
                        try {
                            if (EnergyUtil.voltageParameterIC2) {
                                result = (Double) EnergyUtil.injectEnergyIC2.invoke(tileEntity, sideFrom.getOpposite(), energySendingIC2, 120D);
                            } else {
                                result = (Double) EnergyUtil.injectEnergyIC2.invoke(tileEntity, sideFrom.getOpposite(), energySendingIC2);
                            }
                        } catch (Exception ex) {
                            if (ConfigManagerCore.enableDebug) {
                                ex.printStackTrace();
                            }
                        }
                        sentToAcceptor = currentSending - (float) result / EnergyConfigHandler.TO_IC2_RATIO;
                        if (sentToAcceptor < 0F) {
                            sentToAcceptor = 0F;
                        }
                    } else {
                        sentToAcceptor = 0F;
                    }
                } else if (isRF2Loaded && tileEntity instanceof IEnergyReceiver) {
                    final int currentSendinginRF = (currentSending >= Integer.MAX_VALUE / EnergyConfigHandler.TO_RF_RATIO) ? Integer.MAX_VALUE : (int) (currentSending * EnergyConfigHandler.TO_RF_RATIO);
                    sentToAcceptor = ((IEnergyReceiver) tileEntity).receiveEnergy(sideFrom, currentSendinginRF, false) / EnergyConfigHandler.TO_RF_RATIO;
                } else {
                    sentToAcceptor = 0F;
                }
                if (sentToAcceptor / currentSending > 1.002F && sentToAcceptor > 0.01F) {
                    if (!this.spamstop) {
                        FMLLog.info("Energy network: acceptor took too much energy, offered " + currentSending + ", took " + sentToAcceptor + ". " + tileEntity.toString());
                        this.spamstop = true;
                    }
                    sentToAcceptor = currentSending;
                }
                sent += sentToAcceptor;
            }
        } catch (Exception e) {
            GCLog.severe("DEBUG Energy network loop issue, please report this");
            if (debugTE instanceof TileEntity) {
                GCLog.severe("Problem was likely caused by tile in dim " + GCCoreUtil.getDimensionID(((TileEntity) debugTE).getWorld()) + " at " + ((TileEntity) debugTE).getPos() + " Type:" + debugTE.getClass().getSimpleName());
            }
        }
    }
    if (EnergyNetwork.tickCount % 200 == 0) {
        this.spamstop = false;
    }
    float returnvalue = sent;
    if (returnvalue > this.totalEnergy) {
        returnvalue = this.totalEnergy;
    }
    if (returnvalue < 0F) {
        returnvalue = 0F;
    }
    return returnvalue;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IStrictEnergyAcceptor(mekanism.api.energy.IStrictEnergyAcceptor) IElectrical(micdoodle8.mods.galacticraft.api.transmission.tile.IElectrical) IEnergySink(ic2.api.energy.tile.IEnergySink) IEnergyReceiver(cofh.api.energy.IEnergyReceiver)

Example 4 with Energy

use of ic2.core.block.comp.Energy 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 5 with Energy

use of ic2.core.block.comp.Energy in project Galacticraft by micdoodle8.

the class BasicSink method onChunkUnload.

/**
 * Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
 * Both invalidate and onChunkUnload have to be used.
 */
@Override
public void onChunkUnload() {
    if (addedToEnet && Info.isIc2Available()) {
        MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
        addedToEnet = false;
    }
}
Also used : EnergyTileUnloadEvent(ic2.api.energy.event.EnergyTileUnloadEvent)

Aggregations

EnergyTileUnloadEvent (ic2.api.energy.event.EnergyTileUnloadEvent)4 IEnergyReceiver (cofh.api.energy.IEnergyReceiver)2 IEnergySink (ic2.api.energy.tile.IEnergySink)2 IStrictEnergyAcceptor (mekanism.api.energy.IStrictEnergyAcceptor)2 IElectrical (micdoodle8.mods.galacticraft.api.transmission.tile.IElectrical)2 EnumFacing (net.minecraft.util.EnumFacing)2 DescriptionComponent (de.canitzp.tumat.api.components.DescriptionComponent)1 EnergyComponent (de.canitzp.tumat.api.components.EnergyComponent)1 TextComponent (de.canitzp.tumat.api.components.TextComponent)1 ElectricItem (ic2.api.item.ElectricItem)1 IElectricItem (ic2.api.item.IElectricItem)1 IElectricItemManager (ic2.api.item.IElectricItemManager)1 ISpecialElectricItem (ic2.api.item.ISpecialElectricItem)1 IEnergyStorage (ic2.api.tile.IEnergyStorage)1 TileEntityBlock (ic2.core.block.TileEntityBlock)1 Energy (ic2.core.block.comp.Energy)1 CableType (ic2.core.block.wiring.CableType)1 TileEntityCable (ic2.core.block.wiring.TileEntityCable)1 TileEntityTransformer (ic2.core.block.wiring.TileEntityTransformer)1 ArrayList (java.util.ArrayList)1