use of buildcraft.api.power.IPowerProvider 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;
}
}
}
use of buildcraft.api.power.IPowerProvider in project MineFactoryReloaded by powercrystals.
the class TileEntityGenerator method producePower.
protected final int producePower(int mj) {
BlockPosition ourbp = BlockPosition.fromFactoryTile(this);
for (BlockPosition bp : ourbp.getAdjacent(true)) {
TileEntity te = worldObj.getBlockTileEntity(bp.x, bp.y, bp.z);
if (te == null || !(te instanceof IPowerReceptor)) {
continue;
}
IPowerReceptor ipr = ((IPowerReceptor) te);
IPowerProvider pp = ipr.getPowerProvider();
if (pp != null && pp.preConditions(ipr) && pp.getMinEnergyReceived() <= mj) {
int mjUsed = Math.min(Math.min(pp.getMaxEnergyReceived(), mj), pp.getMaxEnergyStored() - (int) Math.floor(pp.getEnergyStored()));
pp.receiveEnergy(mjUsed, bp.orientation);
mj -= mjUsed;
if (mj <= 0) {
return 0;
}
}
}
return mj;
}
Aggregations