use of universalelectricity.core.electricity.ElectricityPack 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;
}
}
}
Aggregations