Search in sources :

Example 1 with EnergyTileLoadEvent

use of ic2.api.energy.event.EnergyTileLoadEvent in project compactsolars by cpw.

the class BasicSink method onLoaded.

/**
	 * Notification that the TileEntity finished loaded, for advanced uses.
	 * Either onUpdateEntity or onLoaded have to be used.
	 */
public void onLoaded() {
    if (!addedToEnet && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        worldObj = parent.worldObj;
        xCoord = parent.xCoord;
        yCoord = parent.yCoord;
        zCoord = parent.zCoord;
        MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
        addedToEnet = true;
    }
}
Also used : EnergyTileLoadEvent(ic2.api.energy.event.EnergyTileLoadEvent)

Example 2 with EnergyTileLoadEvent

use of ic2.api.energy.event.EnergyTileLoadEvent in project compactsolars by cpw.

the class BasicSource method onLoaded.

/**
	 * Notification that the TileEntity finished loaded, for advanced uses.
	 * Either onUpdateEntity or onLoaded have to be used.
	 */
public void onLoaded() {
    if (!addedToEnet && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        worldObj = parent.worldObj;
        xCoord = parent.xCoord;
        yCoord = parent.yCoord;
        zCoord = parent.zCoord;
        MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
        addedToEnet = true;
    }
}
Also used : EnergyTileLoadEvent(ic2.api.energy.event.EnergyTileLoadEvent)

Example 3 with EnergyTileLoadEvent

use of ic2.api.energy.event.EnergyTileLoadEvent in project MineFactoryReloaded by powercrystals.

the class TileEntityFactoryPowered method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    _energyStored = Math.min(_energyStored, getEnergyStoredMax());
    if (worldObj.isRemote) {
        return;
    }
    if (_addToNetOnNextTick) {
        if (!worldObj.isRemote) {
            MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
        }
        _addToNetOnNextTick = false;
        _isAddedToIC2EnergyNet = true;
    }
    int energyRequired = Math.min(getEnergyStoredMax() - getEnergyStored(), getMaxEnergyPerTick());
    if (energyRequired > 0) {
        IPowerProvider pp = getPowerProvider();
        bcpower: if (pp != null) {
            int mjRequired = energyRequired / energyPerMJ;
            if (mjRequired <= 0)
                break bcpower;
            pp.update(this);
            if (pp.useEnergy(0, mjRequired, false) > 0) {
                int mjGained = (int) (pp.useEnergy(0, mjRequired, true) * energyPerMJ);
                _energyStored += mjGained;
                energyRequired -= mjGained;
            }
        }
        ElectricityPack powerRequested = new ElectricityPack(energyRequired * wPerEnergy / getVoltage(), getVoltage());
        ElectricityPack powerPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, powerRequested);
        _ueBuffer += powerPack.getWatts();
        int energyFromUE = Math.min(_ueBuffer / wPerEnergy, energyRequired);
        _energyStored += energyFromUE;
        energyRequired -= energyFromUE;
        _ueBuffer -= (energyFromUE * wPerEnergy);
    }
    _energyRequiredThisTick = energyRequired;
    setIsActive(_energyStored >= _energyActivation * 2);
    if (failedDrops != null) {
        if (_failedDropTicks < _failedDropTicksMax) {
            _failedDropTicks++;
            return;
        }
        _failedDropTicks = 0;
        if (!doDrop(failedDrops)) {
            setIdleTicks(getIdleTicksMax());
            return;
        }
        failedDrops = null;
    }
    if (Util.isRedstonePowered(this)) {
        setIdleTicks(getIdleTicksMax());
    } else if (_idleTicks > 0) {
        _idleTicks--;
    } else if (_energyStored >= _energyActivation) {
        if (activateMachine()) {
            _energyStored -= _energyActivation;
        }
    }
}
Also used : EnergyTileLoadEvent(ic2.api.energy.event.EnergyTileLoadEvent) ElectricityPack(universalelectricity.core.electricity.ElectricityPack) IPowerProvider(buildcraft.api.power.IPowerProvider)

Aggregations

EnergyTileLoadEvent (ic2.api.energy.event.EnergyTileLoadEvent)3 IPowerProvider (buildcraft.api.power.IPowerProvider)1 ElectricityPack (universalelectricity.core.electricity.ElectricityPack)1