fix a lot of engine code, close #2048
This commit is contained in:
parent
777fee2092
commit
c961de9daf
7 changed files with 41 additions and 60 deletions
|
@ -134,7 +134,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
}
|
||||
|
||||
public double getEnergyLevel() {
|
||||
return energy / getMaxEnergy();
|
||||
return (double)energy / getMaxEnergy();
|
||||
}
|
||||
|
||||
protected EnergyStage computeEnergyStage() {
|
||||
|
@ -266,19 +266,16 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
setPumping(false);
|
||||
}
|
||||
|
||||
// Uncomment for constant power
|
||||
if (constantPower) {
|
||||
if (isRedstonePowered && isActive()) {
|
||||
sendPower();
|
||||
} else {
|
||||
currentOutput = 0;
|
||||
}
|
||||
}
|
||||
|
||||
burn();
|
||||
|
||||
if (!isRedstonePowered) {
|
||||
currentOutput = 0;
|
||||
} else if (constantPower && isRedstonePowered && isActive()) {
|
||||
sendPower();
|
||||
}
|
||||
}
|
||||
|
||||
private double getPowerToExtract() {
|
||||
private int getPowerToExtract() {
|
||||
TileEntity tile = getTileBuffer(orientation).getTile();
|
||||
|
||||
if (tile instanceof IEnergyHandler) {
|
||||
|
@ -293,8 +290,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
PowerReceiver receptor = ((IPowerReceptor) tile)
|
||||
.getPowerReceiver(orientation.getOpposite());
|
||||
|
||||
return extractEnergy(receptor.getMinEnergyReceived() * 10,
|
||||
receptor.getMaxEnergyReceived() * 10, false);
|
||||
return extractEnergy((int) Math.floor(receptor.getMinEnergyReceived() * 10),
|
||||
(int) Math.ceil(receptor.getMaxEnergyReceived() * 10), false);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -317,7 +314,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
orientation.getOpposite(),
|
||||
(int) Math.round(extracted), false);
|
||||
|
||||
extractEnergy(0.0, neededRF, true);
|
||||
extractEnergy(0, neededRF, true);
|
||||
}
|
||||
} else if (tile instanceof IPowerReceptor) {
|
||||
PowerReceiver receptor = ((IPowerReceptor) tile)
|
||||
|
@ -325,10 +322,10 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
|
||||
if (extracted > 0) {
|
||||
double neededMJ = receptor.receiveEnergy(
|
||||
PowerHandler.Type.ENGINE, extracted,
|
||||
PowerHandler.Type.ENGINE, extracted / 10.0,
|
||||
orientation.getOpposite());
|
||||
|
||||
extractEnergy(receptor.getMinEnergyReceived(), neededMJ * 10, true);
|
||||
extractEnergy((int) Math.floor(receptor.getMinEnergyReceived() * 10), (int) Math.ceil(neededMJ * 10), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,10 +385,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
if ((!pipesOnly || tile instanceof IPipeTile) && isPoweredTile(tile, o)) {
|
||||
if ((tile instanceof IPipeTile) && (((IPipeTile) tile).getPipeType() != PipeType.POWER)) {
|
||||
constantPower = false;
|
||||
} else if (tile instanceof IEnergyHandler) {
|
||||
constantPower = true;
|
||||
} else {
|
||||
constantPower = false;
|
||||
constantPower = true;
|
||||
}
|
||||
|
||||
orientation = o;
|
||||
|
@ -505,30 +500,20 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
}
|
||||
}
|
||||
|
||||
public double extractEnergy(double min, double max, boolean doExtract) {
|
||||
if (energy < min) {
|
||||
public int extractEnergy(int min, int max, boolean doExtract) {
|
||||
max = Math.min(max, maxEnergyExtracted());
|
||||
|
||||
if (max < min || energy < min) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double actualMax;
|
||||
int extracted;
|
||||
|
||||
if (max > maxEnergyExtracted()) {
|
||||
actualMax = maxEnergyExtracted();
|
||||
} else {
|
||||
actualMax = max;
|
||||
}
|
||||
|
||||
if (actualMax < min) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double extracted;
|
||||
|
||||
if (energy >= actualMax) {
|
||||
extracted = actualMax;
|
||||
if (energy >= max) {
|
||||
extracted = max;
|
||||
|
||||
if (doExtract) {
|
||||
energy -= actualMax;
|
||||
energy -= max;
|
||||
}
|
||||
} else {
|
||||
extracted = energy;
|
||||
|
@ -569,7 +554,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
return energy;
|
||||
}
|
||||
|
||||
public abstract int getCurrentOutput();
|
||||
public abstract int calculateCurrentOutput();
|
||||
|
||||
@Override
|
||||
public LinkedList<ITrigger> getTriggers() {
|
||||
|
@ -623,12 +608,12 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
|
|||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.round(energy);
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return getEnergyStored(from);
|
||||
return this.getMaxEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -91,7 +91,7 @@ public class TileEngineCreative extends TileEngine {
|
|||
super.engineUpdate();
|
||||
|
||||
if (isRedstonePowered) {
|
||||
addEnergy(getCurrentOutput());
|
||||
addEnergy(calculateCurrentOutput());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,21 +102,21 @@ public class TileEngineCreative extends TileEngine {
|
|||
|
||||
@Override
|
||||
public int maxEnergyReceived() {
|
||||
return getCurrentOutput();
|
||||
return calculateCurrentOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxEnergyExtracted() {
|
||||
return getCurrentOutput();
|
||||
return calculateCurrentOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergy() {
|
||||
return getCurrentOutput();
|
||||
return calculateCurrentOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentOutput() {
|
||||
public int calculateCurrentOutput() {
|
||||
return powerMode.maxPower;
|
||||
}
|
||||
|
||||
|
|
|
@ -173,9 +173,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
|
|||
}
|
||||
}
|
||||
|
||||
if (!this.constantPower) {
|
||||
currentOutput = currentFuel.getPowerPerCycle();
|
||||
}
|
||||
currentOutput = currentFuel.getPowerPerCycle();
|
||||
|
||||
addEnergy(currentFuel.getPowerPerCycle());
|
||||
heat += currentFuel.getPowerPerCycle() * HEAT_PER_RF * getBiomeTempScalar();
|
||||
|
@ -418,7 +416,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentOutput() {
|
||||
public int calculateCurrentOutput() {
|
||||
if (currentFuel == null) {
|
||||
return 0;
|
||||
} else {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class TileEngineLegacy extends TileEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentOutput() {
|
||||
public int calculateCurrentOutput() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,13 +76,11 @@ public class TileEngineStone extends TileEngineWithInventory {
|
|||
if (burnTime > 0) {
|
||||
burnTime--;
|
||||
|
||||
int output = getCurrentOutput();
|
||||
currentOutput = calculateCurrentOutput();
|
||||
|
||||
if (!constantPower) {
|
||||
currentOutput = output; // Comment out for constant power
|
||||
}
|
||||
|
||||
addEnergy(output);
|
||||
addEnergy(currentOutput);
|
||||
} else {
|
||||
currentOutput = 0;
|
||||
}
|
||||
|
||||
if (burnTime == 0 && isRedstonePowered) {
|
||||
|
@ -157,7 +155,7 @@ public class TileEngineStone extends TileEngineWithInventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentOutput() {
|
||||
public int calculateCurrentOutput() {
|
||||
double e = TARGET_OUTPUT * getMaxEnergy() - energy;
|
||||
esum = MathUtils.clamp(esum + e, -eLimit, eLimit);
|
||||
return (int) Math.round(MathUtils.clamp(e * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT));
|
||||
|
|
|
@ -104,7 +104,7 @@ public class TileEngineWood extends TileEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentOutput() {
|
||||
public int calculateCurrentOutput() {
|
||||
return OUTPUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class GuiEngine extends GuiBuildCraft {
|
|||
|
||||
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.energy"), x + 22, y + 8, headerColour);
|
||||
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.currentOutput") + ":", x + 22, y + 20, subheaderColour);
|
||||
fontRendererObj.drawString(String.format("%d RF/t", engine.getCurrentOutput()),
|
||||
fontRendererObj.drawString(String.format("%d RF/t", engine.currentOutput),
|
||||
x + 22, y + 32, textColour);
|
||||
fontRendererObj.drawStringWithShadow(StringUtils.localize("gui.stored") + ":", x + 22, y + 44, subheaderColour);
|
||||
fontRendererObj.drawString(String.format("%d RF", engine.getEnergyStored()), x + 22,
|
||||
|
@ -65,7 +65,7 @@ public abstract class GuiEngine extends GuiBuildCraft {
|
|||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return String.format("%d RF/t", engine.getCurrentOutput());
|
||||
return String.format("%d RF/t", engine.currentOutput);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue