Convert Power API to use Double instead of Float

Closes #1288
This commit is contained in:
CovertJaguar 2014-01-03 01:17:19 -08:00
parent 3b0a047570
commit 6c73c1a070
15 changed files with 96 additions and 100 deletions

View file

@ -28,7 +28,7 @@ public interface ILaserTarget {
*
* @param energy
*/
void receiveLaserEnergy(float energy);
void receiveLaserEnergy(double energy);
/**
* Return true if the Tile Entity object is no longer a valid target. For

View file

@ -65,7 +65,7 @@ public final class PowerHandler {
public static final float DEFAULT_POWERLOSS = 1F;
public static final float MIN_POWERLOSS = 0.01F;
private final float powerLoss;
private final double powerLoss;
public PerditionCalculator() {
powerLoss = DEFAULT_POWERLOSS;
@ -76,7 +76,7 @@ public final class PowerHandler {
*
* @param powerLoss power loss per tick
*/
public PerditionCalculator(float powerLoss) {
public PerditionCalculator(double powerLoss) {
if (powerLoss < MIN_POWERLOSS) {
powerLoss = MIN_POWERLOSS;
}
@ -93,7 +93,7 @@ public final class PowerHandler {
* @param ticksPassed ticks since the last time this function was called
* @return
*/
public float applyPerdition(PowerHandler powerHandler, float current, long ticksPassed) {
public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) {
// float prev = current;
current -= powerLoss * ticksPassed;
if (current < 0) {
@ -110,16 +110,16 @@ public final class PowerHandler {
*
* @return percent of input to tax
*/
public float getTaxPercent() {
public double getTaxPercent() {
return 0;
}
}
public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator();
private float minEnergyReceived;
private float maxEnergyReceived;
private float maxEnergyStored;
private float activationEnergy;
private float energyStored = 0;
private double minEnergyReceived;
private double maxEnergyReceived;
private double maxEnergyStored;
private double activationEnergy;
private double energyStored = 0;
private final SafeTimeTracker doWorkTracker = new SafeTimeTracker();
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker();
private final SafeTimeTracker perditionTracker = new SafeTimeTracker();
@ -145,23 +145,23 @@ public final class PowerHandler {
return receiver;
}
public float getMinEnergyReceived() {
public double getMinEnergyReceived() {
return minEnergyReceived;
}
public float getMaxEnergyReceived() {
public double getMaxEnergyReceived() {
return maxEnergyReceived;
}
public float getMaxEnergyStored() {
public double getMaxEnergyStored() {
return maxEnergyStored;
}
public float getActivationEnergy() {
public double getActivationEnergy() {
return activationEnergy;
}
public float getEnergyStored() {
public double getEnergyStored() {
return energyStored;
}
@ -183,7 +183,7 @@ public final class PowerHandler {
* store. Values tend to range between 100 and 5000. With 1000 and 1500
* being common.
*/
public void configure(float minEnergyReceived, float maxEnergyReceived, float activationEnergy, float maxStoredEnergy) {
public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, double maxStoredEnergy) {
if (minEnergyReceived > maxEnergyReceived) {
maxEnergyReceived = minEnergyReceived;
}
@ -256,7 +256,7 @@ public final class PowerHandler {
private void applyPerdition() {
if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) {
float newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay());
if (newEnergy == 0 || newEnergy < energyStored)
energyStored = newEnergy;
else
@ -296,10 +296,10 @@ public final class PowerHandler {
* @param doUse
* @return amount used
*/
public float useEnergy(float min, float max, boolean doUse) {
public double useEnergy(double min, double max, boolean doUse) {
applyPerdition();
float result = 0;
double result = 0;
if (energyStored >= min) {
if (energyStored <= max) {
@ -329,7 +329,7 @@ public final class PowerHandler {
public void readFromNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = data.getCompoundTag(tag);
energyStored = nbt.getFloat("storedEnergy");
energyStored = nbt.getDouble("energyStored");
}
public void writeToNBT(NBTTagCompound data) {
@ -338,7 +338,7 @@ public final class PowerHandler {
public void writeToNBT(NBTTagCompound data, String tag) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("storedEnergy", energyStored);
nbt.setDouble("energyStored", energyStored);
data.setCompoundTag(tag, nbt);
}
@ -347,23 +347,23 @@ public final class PowerHandler {
private PowerReceiver() {
}
public float getMinEnergyReceived() {
public double getMinEnergyReceived() {
return minEnergyReceived;
}
public float getMaxEnergyReceived() {
public double getMaxEnergyReceived() {
return maxEnergyReceived;
}
public float getMaxEnergyStored() {
public double getMaxEnergyStored() {
return maxEnergyStored;
}
public float getActivationEnergy() {
public double getActivationEnergy() {
return activationEnergy;
}
public float getEnergyStored() {
public double getEnergyStored() {
return energyStored;
}
@ -380,7 +380,7 @@ public final class PowerHandler {
*
* @return
*/
public float powerRequest() {
public double powerRequest() {
update();
return Math.min(maxEnergyReceived, maxEnergyStored - energyStored);
}
@ -394,8 +394,8 @@ public final class PowerHandler {
* @param from
* @return the amount of power used
*/
public float receiveEnergy(Type source, final float quantity, ForgeDirection from) {
float used = quantity;
public double receiveEnergy(Type source, final double quantity, ForgeDirection from) {
double used = quantity;
if (source == Type.ENGINE) {
if (used < minEnergyReceived) {
return 0;
@ -426,7 +426,7 @@ public final class PowerHandler {
*
* @return the amount the power changed by
*/
public float addEnergy(float quantity) {
public double addEnergy(double quantity) {
energyStored += quantity;
if (energyStored > maxEnergyStored) {
@ -442,7 +442,7 @@ public final class PowerHandler {
return quantity;
}
public void setEnergy(float quantity) {
public void setEnergy(double quantity) {
this.energyStored = quantity;
validateEnergy();
}

View file

@ -16,9 +16,9 @@ public class EntityEnergyLaser extends EntityLaser {
public static final short POWER_AVERAGING = 100;
public int displayStage = 0;
private final float power[] = new float[POWER_AVERAGING];
private final double power[] = new double[POWER_AVERAGING];
private int powerIndex = 0;
private float powerAverage = 0;
private double powerAverage = 0;
public EntityEnergyLaser(World world) {
super(world);
@ -28,7 +28,7 @@ public class EntityEnergyLaser extends EntityLaser {
super(world, head, tail);
}
public void pushPower(float received) {
public void pushPower(double received) {
powerAverage -= power[powerIndex];
powerAverage += received;
@ -40,7 +40,7 @@ public class EntityEnergyLaser extends EntityLaser {
}
}
public float getPowerAverage() {
public double getPowerAverage() {
return powerAverage / POWER_AVERAGING;
}

View file

@ -11,9 +11,7 @@ import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
@ -52,12 +50,12 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
protected int progressPart = 0;
protected boolean lastPower = false;
protected PowerHandler powerHandler;
public float currentOutput = 0;
public double currentOutput = 0;
public boolean isRedstonePowered = false;
private boolean checkOrienation = false;
private TileBuffer[] tileCache;
public float progress;
public float energy;
public double energy;
public float heat = MIN_HEAT;
//
public @TileNetworkData
@ -86,7 +84,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
return false;
}
public float getEnergyLevel() {
public double getEnergyLevel() {
return energy / getMaxEnergy();
}
@ -120,7 +118,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
public void updateHeatLevel() {
heat = ((MAX_HEAT - MIN_HEAT) * getEnergyLevel()) + MIN_HEAT;
heat = (float) ((MAX_HEAT - MIN_HEAT) * getEnergyLevel()) + MIN_HEAT;
}
public float getHeatLevel() {
@ -216,7 +214,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
burn();
}
private float getPowerToExtract() {
private double getPowerToExtract() {
TileEntity tile = getTileBuffer(orientation).getTile();
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
return extractEnergy(receptor.getMinEnergyReceived(), receptor.getMaxEnergyReceived(), false); // Comment out for constant power
@ -228,9 +226,9 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
if (isPoweredTile(tile, orientation)) {
PowerReceiver receptor = ((IPowerReceptor) tile).getPowerReceiver(orientation.getOpposite());
float extracted = getPowerToExtract();
double extracted = getPowerToExtract();
if (extracted > 0) {
float needed = receptor.receiveEnergy(PowerHandler.Type.ENGINE, extracted, orientation.getOpposite());
double needed = receptor.receiveEnergy(PowerHandler.Type.ENGINE, extracted, orientation.getOpposite());
extractEnergy(receptor.getMinEnergyReceived(), needed, true); // Comment out for constant power
// currentOutput = extractEnergy(0, needed, true); // Uncomment for constant power
}
@ -318,10 +316,8 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
super.readFromNBT(data);
orientation = ForgeDirection.getOrientation(data.getInteger("orientation"));
progress = data.getFloat("progress");
energy = data.getFloat("energyF");
NBTBase tag = data.getTag("heat");
if (tag instanceof NBTTagFloat)
heat = data.getFloat("heat");
energy = data.getDouble("energy");
heat = data.getFloat("heat");
}
@Override
@ -329,19 +325,19 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
super.writeToNBT(data);
data.setInteger("orientation", orientation.ordinal());
data.setFloat("progress", progress);
data.setFloat("energyF", energy);
data.setDouble("energy", energy);
data.setFloat("heat", heat);
}
public void getGUINetworkData(int id, int value) {
switch (id) {
case 0:
int iEnergy = Math.round(energy * 10);
int iEnergy = (int) Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff0000) | (value & 0xffff);
energy = iEnergy / 10;
break;
case 1:
iEnergy = Math.round(energy * 10);
iEnergy = (int) Math.round(energy * 10);
iEnergy = (iEnergy & 0xffff) | ((value & 0xffff) << 16);
energy = iEnergy / 10;
break;
@ -355,9 +351,9 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
}
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
iCrafting.sendProgressBarUpdate(containerEngine, 0, Math.round(energy * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (Math.round(energy * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 0, (int) Math.round(energy * 10) & 0xffff);
iCrafting.sendProgressBarUpdate(containerEngine, 1, (int) (Math.round(energy * 10) & 0xffff0000) >> 16);
iCrafting.sendProgressBarUpdate(containerEngine, 2, (int) Math.round(currentOutput * 10));
iCrafting.sendProgressBarUpdate(containerEngine, 3, Math.round(heat * 100));
}
@ -379,7 +375,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
addEnergy(powerHandler.useEnergy(1, maxEnergyReceived(), true) * 0.95F);
}
public void addEnergy(float addition) {
public void addEnergy(double addition) {
energy += addition;
if (getEnergyStage() == EnergyStage.OVERHEAT) {
@ -391,11 +387,11 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
energy = getMaxEnergy();
}
public float extractEnergy(float min, float max, boolean doExtract) {
public double extractEnergy(double min, double max, boolean doExtract) {
if (energy < min)
return 0;
float actualMax;
double actualMax;
if (max > maxEnergyExtracted())
actualMax = maxEnergyExtracted();
@ -405,7 +401,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
if (actualMax < min)
return 0;
float extracted;
double extracted;
if (energy >= actualMax) {
extracted = actualMax;
@ -427,23 +423,23 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
return false;
}
public abstract float getMaxEnergy();
public abstract double getMaxEnergy();
public float minEnergyReceived() {
public double minEnergyReceived() {
return 2;
}
public abstract float maxEnergyReceived();
public abstract double maxEnergyReceived();
public abstract float maxEnergyExtracted();
public abstract double maxEnergyExtracted();
public abstract float explosionRange();
public float getEnergyStored() {
public double getEnergyStored() {
return energy;
}
public abstract float getCurrentOutput();
public abstract double getCurrentOutput();
@Override
public LinkedList<ITrigger> getTriggers() {

View file

@ -396,22 +396,22 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
}
@Override
public float maxEnergyReceived() {
public double maxEnergyReceived() {
return 2000;
}
@Override
public float maxEnergyExtracted() {
public double maxEnergyExtracted() {
return 500;
}
@Override
public float getMaxEnergy() {
public double getMaxEnergy() {
return 10000;
}
@Override
public float getCurrentOutput() {
public double getCurrentOutput() {
if (currentFuel == null) {
return 0;
}

View file

@ -47,12 +47,12 @@ public class TileEngineLegacy extends TileEngine {
}
@Override
public float getMaxEnergy() {
public double getMaxEnergy() {
return 1;
}
@Override
public float maxEnergyReceived() {
public double maxEnergyReceived() {
return 0;
}
@ -72,12 +72,12 @@ public class TileEngineLegacy extends TileEngine {
}
@Override
public float getCurrentOutput() {
public double getCurrentOutput() {
return 1;
}
@Override
public float maxEnergyExtracted() {
public double maxEnergyExtracted() {
return 1;
}
}

View file

@ -22,7 +22,7 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.core.utils.MathUtils;
import buildcraft.energy.gui.ContainerEngine;
public class TileEngineStone extends TileEngineWithInventory {
@ -32,10 +32,10 @@ public class TileEngineStone extends TileEngineWithInventory {
final float TARGET_OUTPUT = 0.375f;
final float kp = 1f;
final float ki = 0.05f;
final float eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki;
final double eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki;
int burnTime = 0;
int totalBurnTime = 0;
float esum = 0;
double esum = 0;
public TileEngineStone() {
super(1);
@ -69,7 +69,7 @@ public class TileEngineStone extends TileEngineWithInventory {
if (burnTime > 0) {
burnTime--;
float output = getCurrentOutput();
double output = getCurrentOutput();
currentOutput = output; // Comment out for constant power
addEnergy(output);
}
@ -131,25 +131,25 @@ public class TileEngineStone extends TileEngineWithInventory {
}
@Override
public float maxEnergyReceived() {
public double maxEnergyReceived() {
return 200;
}
@Override
public float maxEnergyExtracted() {
public double maxEnergyExtracted() {
return 100;
}
@Override
public float getMaxEnergy() {
public double getMaxEnergy() {
return 1000;
}
@Override
public float getCurrentOutput() {
float e = TARGET_OUTPUT * getMaxEnergy() - energy;
esum = Math.min(Math.max(esum + e, -eLimit), eLimit);
return Math.min(Math.max(e * kp + esum * ki, MIN_OUTPUT), MAX_OUTPUT);
public double getCurrentOutput() {
double e = TARGET_OUTPUT * getMaxEnergy() - energy;
esum = MathUtils.clamp(esum + e, -eLimit, eLimit);
return MathUtils.clamp(e * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT);
}
@Override

View file

@ -28,18 +28,18 @@ public class TileEngineWood extends TileEngine {
}
@Override
public float minEnergyReceived() {
public double minEnergyReceived() {
return 0;
}
@Override
public float maxEnergyReceived() {
public double maxEnergyReceived() {
return 50;
}
@Override
protected EnergyStage computeEnergyStage() {
float energyLevel = getEnergyLevel();
double energyLevel = getEnergyLevel();
if (energyLevel < 0.25f)
return EnergyStage.BLUE;
else if (energyLevel < 0.5f)
@ -91,17 +91,17 @@ public class TileEngineWood extends TileEngine {
}
@Override
public float getMaxEnergy() {
public double getMaxEnergy() {
return 100;
}
@Override
public float getCurrentOutput() {
public double getCurrentOutput() {
return OUTPUT;
}
@Override
public float maxEnergyExtracted() {
public double maxEnergyExtracted() {
return 1 + PowerHandler.PerditionCalculator.MIN_POWERLOSS;
}
}

View file

@ -150,9 +150,9 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
}
super.updateEntity();
if (inProcess) {
float energyToUse = 2 + powerHandler.getEnergyStored() / 500;
double energyToUse = 2 + powerHandler.getEnergyStored() / 500;
float energy = powerHandler.useEnergy(energyToUse, energyToUse, true);
double energy = powerHandler.useEnergy(energyToUse, energyToUse, true);
if (energy > 0) {
moveHead(0.1 + energy / 200F);

View file

@ -158,7 +158,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
if (!time.markTimeIfDelay(worldObj, currentRecipe.timeRequired))
return;
float energyUsed = powerHandler.useEnergy(currentRecipe.energyCost, currentRecipe.energyCost, true);
double energyUsed = powerHandler.useEnergy(currentRecipe.energyCost, currentRecipe.energyCost, true);
if (energyUsed != 0) {
if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) {

View file

@ -97,7 +97,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
}
// Consume power and transfer it to the table.
float power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
double power = powerHandler.useEnergy(0, getMaxPowerSent(), true);
laserTarget.receiveLaserEnergy(power);
if (laser != null) {
@ -113,7 +113,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction
return 4;
}
protected void onPowerSent(float power) {
protected void onPowerSent(double power) {
}
protected boolean canFindTable() {

View file

@ -76,7 +76,7 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
}
@Override
public void receiveLaserEnergy(float energy) {
public void receiveLaserEnergy(double energy) {
this.energy += energy;
recentEnergy[tick] += energy;
}

View file

@ -162,7 +162,7 @@ public class PipeTransportPower extends PipeTransport {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
if (prov != null && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
watts = (float) prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
} else if (tiles[j] instanceof TileGenericPipe) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
@ -202,7 +202,7 @@ public class PipeTransportPower extends PipeTransport {
for (int i = 0; i < 6; ++i) {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[i]);
if (prov != null) {
float request = prov.powerRequest();
float request = (float) prov.powerRequest();
if (request > 0) {
requestEnergy(ForgeDirection.VALID_DIRECTIONS[i], request);

View file

@ -207,7 +207,7 @@ public class PipeItemsObsidian extends Pipe<PipeTransportItems> implements IPowe
CoreProxy.proxy.obsidianPipePickup(container.worldObj, item, this.container);
float energyUsed = powerHandler.useEnergy(distance, contained.stackSize * distance, true);
double energyUsed = powerHandler.useEnergy(distance, contained.stackSize * distance, true);
if (distance == 0 || energyUsed / distance == contained.stackSize) {
stack = contained;

View file

@ -92,7 +92,7 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
return;
}
float energyToRemove;
double energyToRemove;
if (powerHandler.getEnergyStored() > 40) {
energyToRemove = powerHandler.getEnergyStored() / 40 + 4;
@ -107,7 +107,7 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerRec
if (!powerSources[o.ordinal()])
continue;
float energyUsable = powerHandler.useEnergy(0, energyToRemove, false);
float energyUsable = (float) powerHandler.useEnergy(0, energyToRemove, false);
float energySent = transport.receiveEnergy(o, energyUsable);
if (energySent > 0) {