mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 07:55:41 +00:00
#297 Engines overheating
This commit is contained in:
1 parent
1e9101e862
commit
e5ff9abac8
1 file changed
+46
-50
@@ -9,15 +9,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.enderio.conduit.power.PowerConduitNetwork.ReceptorEntry;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.enderio.power.PowerInterface;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
@@ -70,14 +66,14 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
public float getPowerInCapacitorBanks() {
|
||||
if (capSupply == null) {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
return capSupply.stored;
|
||||
}
|
||||
|
||||
public float getMaxPowerInCapacitorBanks() {
|
||||
if (capSupply == null) {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
return capSupply.maxCap;
|
||||
@@ -88,7 +84,7 @@ public class NetworkPowerManager {
|
||||
Set<PowerInterface> done = new HashSet<PowerInterface>();
|
||||
for (ReceptorEntry re : receptors) {
|
||||
PowerInterface powerReceptor = re.powerInterface;
|
||||
if (!done.contains(powerReceptor)) {
|
||||
if(!done.contains(powerReceptor)) {
|
||||
done.add(powerReceptor);
|
||||
result += powerReceptor.getEnergyStored(re.direction);
|
||||
}
|
||||
@@ -101,7 +97,7 @@ public class NetworkPowerManager {
|
||||
Set<PowerInterface> done = new HashSet<PowerInterface>();
|
||||
for (ReceptorEntry re : receptors) {
|
||||
PowerInterface powerReceptor = re.powerInterface;
|
||||
if (!done.contains(powerReceptor)) {
|
||||
if(!done.contains(powerReceptor)) {
|
||||
done.add(powerReceptor);
|
||||
result += powerReceptor.getMaxEnergyStored(re.direction);
|
||||
}
|
||||
@@ -126,19 +122,19 @@ public class NetworkPowerManager {
|
||||
float available = energyStored + capSupply.canExtract;
|
||||
float wasAvailable = available;
|
||||
|
||||
if (available <= 0 || (receptors.isEmpty() && storageReceptors.isEmpty())) {
|
||||
if(available <= 0 || (receptors.isEmpty() && storageReceptors.isEmpty())) {
|
||||
trackerEndTick();
|
||||
return;
|
||||
}
|
||||
|
||||
while (available > 0 && appliedCount < numReceptors) {
|
||||
|
||||
if (!receptors.isEmpty() && !receptorIterator.hasNext()) {
|
||||
if(!receptors.isEmpty() && !receptorIterator.hasNext()) {
|
||||
receptorIterator = receptors.listIterator();
|
||||
}
|
||||
|
||||
ReceptorEntry r = receptorIterator.next();
|
||||
if (r.emmiter.getPowerHandler().isPowerSource(r.direction)) {
|
||||
if(r.emmiter.getPowerHandler().isPowerSource(r.direction)) {
|
||||
|
||||
// do a summy recieve or recieve energy counter will never tick down
|
||||
float es = r.emmiter.getPowerHandler().getEnergyStored();
|
||||
@@ -149,7 +145,7 @@ public class NetworkPowerManager {
|
||||
} else {
|
||||
|
||||
PowerInterface pp = r.powerInterface;
|
||||
if (pp != null) {
|
||||
if(pp != null) {
|
||||
|
||||
float used = 0;
|
||||
float reservedForEntry = removeReservedEnergy(r);
|
||||
@@ -158,9 +154,9 @@ public class NetworkPowerManager {
|
||||
float requested = pp.getPowerRequest(r.direction.getOpposite());
|
||||
|
||||
// If it is possible to supply the minimum amount of energy
|
||||
if (pp.getMinEnergyReceived(r.direction) <= r.emmiter.getMaxEnergyExtracted(r.direction)) {
|
||||
if(pp.getMinEnergyReceived(r.direction) <= r.emmiter.getMaxEnergyExtracted(r.direction) && requested > 0) {
|
||||
// Buffer energy if we can't meet it now
|
||||
if (pp.getMinEnergyReceived(r.direction) > canOffer && requested > 0) {
|
||||
if(pp.getMinEnergyReceived(r.direction) > canOffer) {
|
||||
reserveEnergy(r, canOffer);
|
||||
used += canOffer;
|
||||
} else {
|
||||
@@ -170,7 +166,7 @@ public class NetworkPowerManager {
|
||||
available -= used;
|
||||
}
|
||||
|
||||
if (available <= 0) {
|
||||
if(available <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -184,19 +180,19 @@ public class NetworkPowerManager {
|
||||
energyStored -= used;
|
||||
|
||||
float capBankChange = 0;
|
||||
if (energyStored < 0) {
|
||||
if(energyStored < 0) {
|
||||
// not enough so get the rest from the capacitor bank
|
||||
capBankChange = energyStored;
|
||||
energyStored = 0;
|
||||
} else if (energyStored > 0) {
|
||||
} else if(energyStored > 0) {
|
||||
// push as much as we can back to the cap banks
|
||||
capBankChange = Math.min(energyStored, capSupply.canFill);
|
||||
energyStored -= capBankChange;
|
||||
}
|
||||
|
||||
if (capBankChange < 0) {
|
||||
if(capBankChange < 0) {
|
||||
capSupply.remove(Math.abs(capBankChange));
|
||||
} else if (capBankChange > 0) {
|
||||
} else if(capBankChange > 0) {
|
||||
capSupply.add(capBankChange);
|
||||
}
|
||||
|
||||
@@ -211,11 +207,11 @@ public class NetworkPowerManager {
|
||||
|
||||
private void trackerStartTick() {
|
||||
|
||||
if (!Config.detailedPowerTrackingEnabled) {
|
||||
if(!Config.detailedPowerTrackingEnabled) {
|
||||
return;
|
||||
}
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
if (con.hasExternalConnections()) {
|
||||
if(con.hasExternalConnections()) {
|
||||
PowerTracker tracker = getOrCreateTracker(con);
|
||||
tracker.tickStart(con.getPowerHandler().getEnergyStored());
|
||||
}
|
||||
@@ -223,31 +219,31 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
private void trackerSend(IPowerConduit con, float sent, boolean fromBank) {
|
||||
if (!fromBank) {
|
||||
if(!fromBank) {
|
||||
networkPowerTracker.powerSent(sent);
|
||||
}
|
||||
if (!Config.detailedPowerTrackingEnabled) {
|
||||
if(!Config.detailedPowerTrackingEnabled) {
|
||||
return;
|
||||
}
|
||||
getOrCreateTracker(con).powerSent(sent);
|
||||
}
|
||||
|
||||
private void trackerRecieve(IPowerConduit con, float recieved, boolean fromBank) {
|
||||
if (!fromBank) {
|
||||
if(!fromBank) {
|
||||
networkPowerTracker.powerRecieved(recieved);
|
||||
}
|
||||
if (!Config.detailedPowerTrackingEnabled) {
|
||||
if(!Config.detailedPowerTrackingEnabled) {
|
||||
return;
|
||||
}
|
||||
getOrCreateTracker(con).powerRecieved(recieved);
|
||||
}
|
||||
|
||||
private void trackerEndTick() {
|
||||
if (!Config.detailedPowerTrackingEnabled) {
|
||||
if(!Config.detailedPowerTrackingEnabled) {
|
||||
return;
|
||||
}
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
if (con.hasExternalConnections()) {
|
||||
if(con.hasExternalConnections()) {
|
||||
PowerTracker tracker = getOrCreateTracker(con);
|
||||
tracker.tickEnd(con.getPowerHandler().getEnergyStored());
|
||||
}
|
||||
@@ -256,7 +252,7 @@ public class NetworkPowerManager {
|
||||
|
||||
private PowerTracker getOrCreateTracker(IPowerConduit con) {
|
||||
PowerTracker result = powerTrackers.get(con);
|
||||
if (result == null) {
|
||||
if(result == null) {
|
||||
result = new PowerTracker();
|
||||
powerTrackers.put(con, result);
|
||||
}
|
||||
@@ -265,7 +261,7 @@ public class NetworkPowerManager {
|
||||
|
||||
private void updateActiveState() {
|
||||
boolean active;
|
||||
if (energyStored > 0) {
|
||||
if(energyStored > 0) {
|
||||
ticksWithNoPower = 0;
|
||||
active = true;
|
||||
} else {
|
||||
@@ -274,7 +270,7 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
boolean doRender = active != lastActiveValue && (active || (!active && ticksWithNoPower > updateRenderTicks));
|
||||
if (doRender) {
|
||||
if(doRender) {
|
||||
lastActiveValue = active;
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
con.setActive(active);
|
||||
@@ -284,7 +280,7 @@ public class NetworkPowerManager {
|
||||
|
||||
private float removeReservedEnergy(ReceptorEntry r) {
|
||||
StarveBuffer starveBuf = starveBuffers.remove(r.coord);
|
||||
if (starveBuf == null) {
|
||||
if(starveBuf == null) {
|
||||
return 0;
|
||||
}
|
||||
float result = starveBuf.stored;
|
||||
@@ -298,20 +294,20 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
private void checkReserves() {
|
||||
if (reserved > maxEnergyStored * 0.9) {
|
||||
if(reserved > maxEnergyStored * 0.9) {
|
||||
starveBuffers.clear();
|
||||
reserved = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void distributeStorageToConduits() {
|
||||
if (maxEnergyStored <= 0 || energyStored <= 0) {
|
||||
if(maxEnergyStored <= 0 || energyStored <= 0) {
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
con.getPowerHandler().setEnergy(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (energyStored > maxEnergyStored) {
|
||||
if(energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
|
||||
@@ -319,7 +315,7 @@ public class NetworkPowerManager {
|
||||
float energyLeft = energyStored;
|
||||
float given = 0;
|
||||
for (IPowerConduit con : network.getConduits()) {
|
||||
if (energyLeft >= 0) {
|
||||
if(energyLeft >= 0) {
|
||||
// NB: use ceil to ensure we dont through away any energy due to
|
||||
// rounding
|
||||
// errors
|
||||
@@ -347,7 +343,7 @@ public class NetworkPowerManager {
|
||||
energyStored += con.getPowerHandler().getEnergyStored();
|
||||
}
|
||||
|
||||
if (energyStored > maxEnergyStored) {
|
||||
if(energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
|
||||
@@ -357,7 +353,7 @@ public class NetworkPowerManager {
|
||||
receptors.clear();
|
||||
storageReceptors.clear();
|
||||
for (ReceptorEntry rec : network.getPowerReceptors()) {
|
||||
if (rec.powerInterface.getDelegate() instanceof TileCapacitorBank) {
|
||||
if(rec.powerInterface.getDelegate() instanceof TileCapacitorBank) {
|
||||
storageReceptors.add(rec);
|
||||
} else {
|
||||
receptors.add(rec);
|
||||
@@ -384,7 +380,7 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
private float minAbs(float amount, float limit) {
|
||||
if (amount < 0) {
|
||||
if(amount < 0) {
|
||||
return Math.max(amount, -limit);
|
||||
} else {
|
||||
return Math.min(amount, limit);
|
||||
@@ -417,20 +413,20 @@ public class NetworkPowerManager {
|
||||
for (ReceptorEntry rec : storageReceptors) {
|
||||
TileCapacitorBank cb = (TileCapacitorBank) rec.powerInterface.getDelegate();
|
||||
|
||||
if (!capBanks.contains(cb)) {
|
||||
if(!capBanks.contains(cb)) {
|
||||
stored += cb.getEnergyStored();
|
||||
maxCap += cb.getMaxEnergyStored();
|
||||
capBanks.add(cb);
|
||||
}
|
||||
|
||||
float canGet = 0;
|
||||
if (cb.isOutputEnabled()) {
|
||||
if(cb.isOutputEnabled()) {
|
||||
canGet = Math.min(cb.getEnergyStored(), cb.getMaxOutput());
|
||||
canGet = Math.min(canGet, rec.emmiter.getMaxEnergyRecieved(rec.direction));
|
||||
canExtract += canGet;
|
||||
}
|
||||
float canFill = 0;
|
||||
if (cb.isInputEnabled()) {
|
||||
if(cb.isInputEnabled()) {
|
||||
canFill = Math.min(cb.getMaxEnergyStored() - cb.getEnergyStored(), cb.getMaxInput());
|
||||
canFill = Math.min(canFill, rec.emmiter.getMaxEnergyExtracted(rec.direction));
|
||||
this.canFill += canFill;
|
||||
@@ -440,13 +436,13 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
filledRatio = 0;
|
||||
if (maxCap > 0) {
|
||||
if(maxCap > 0) {
|
||||
filledRatio = stored / maxCap;
|
||||
}
|
||||
}
|
||||
|
||||
void balance() {
|
||||
if (enteries.size() < 2) {
|
||||
if(enteries.size() < 2) {
|
||||
return;
|
||||
}
|
||||
init();
|
||||
@@ -454,7 +450,7 @@ public class NetworkPowerManager {
|
||||
int canAdd = 0;
|
||||
for (CapBankSupplyEntry entry : enteries) {
|
||||
entry.calcToBalance(filledRatio);
|
||||
if (entry.toBalance < 0) {
|
||||
if(entry.toBalance < 0) {
|
||||
canRemove += -entry.toBalance;
|
||||
} else {
|
||||
canAdd += entry.toBalance;
|
||||
@@ -473,7 +469,7 @@ public class NetworkPowerManager {
|
||||
|
||||
for (int j = i + 1; j < enteries.size() && toTranfser > 0; j++) {
|
||||
CapBankSupplyEntry to = enteries.get(j);
|
||||
if (Math.signum(amount) != Math.signum(to.toBalance)) {
|
||||
if(Math.signum(amount) != Math.signum(to.toBalance)) {
|
||||
float toAmount = Math.min(toTranfser, Math.abs(to.toBalance));
|
||||
to.capBank.addEnergy(toAmount * Math.signum(to.toBalance));
|
||||
toTranfser -= toAmount;
|
||||
@@ -485,7 +481,7 @@ public class NetworkPowerManager {
|
||||
}
|
||||
|
||||
void remove(float amount) {
|
||||
if (canExtract <= 0 || amount <= 0) {
|
||||
if(canExtract <= 0 || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
float ratio = amount / canExtract;
|
||||
@@ -497,14 +493,14 @@ public class NetworkPowerManager {
|
||||
entry.capBank.addEnergy(-(float) use);
|
||||
trackerRecieve(entry.emmiter, (float) use, true);
|
||||
amount -= use;
|
||||
if (amount == 0) {
|
||||
if(amount == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void add(float amount) {
|
||||
if (canFill <= 0 || amount <= 0) {
|
||||
if(canFill <= 0 || amount <= 0) {
|
||||
return;
|
||||
}
|
||||
float ratio = amount / canFill;
|
||||
@@ -516,7 +512,7 @@ public class NetworkPowerManager {
|
||||
entry.capBank.addEnergy((float) add);
|
||||
trackerSend(entry.emmiter, (float) add, true);
|
||||
amount -= add;
|
||||
if (amount == 0) {
|
||||
if(amount == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -541,7 +537,7 @@ public class NetworkPowerManager {
|
||||
void calcToBalance(float targetRatio) {
|
||||
float targetAmount = capBank.getMaxEnergyStored() * targetRatio;
|
||||
toBalance = targetAmount - capBank.getEnergyStored();
|
||||
if (toBalance < 0) {
|
||||
if(toBalance < 0) {
|
||||
toBalance = Math.max(toBalance, -canExtract);
|
||||
} else {
|
||||
toBalance = Math.min(toBalance, canFill);
|
||||
|
||||
Reference in new issue
Block a user