- Fixed double power production

- Buffered consumers no longer request power when full
This commit is contained in:
Timmeey86
2018-12-01 14:31:01 +01:00
parent b4aba3d263
commit 982c9bf964
4 changed files with 23 additions and 16 deletions

View File

@@ -15,13 +15,8 @@ import java.io.DataOutput;
import java.io.IOException;
public class PowerGenerator extends PowerDistributor{
/** The amount of power produced per tick. */
/** The amount of power produced per tick in case of an efficiency of 1.0, which currently represents 200%. */
protected float powerProduction;
/** The maximum possible efficiency for this generator. Supply values larger than 1.0f if more than 100% is possible.
* This could be the case when e.g. an item with 100% flammability is the reference point, but a more effective liquid
* can be supplied as an alternative.
*/
protected float maxEfficiency = 1.0f;
public BlockStat generationType = BlockStat.basePowerGeneration;
public PowerGenerator(String name){
@@ -39,8 +34,9 @@ public class PowerGenerator extends PowerDistributor{
@Override
public float getPowerProduction(Tile tile){
// Multiply all efficiencies by two since 0.5 = 100% efficiency
return powerProduction * tile.<GeneratorEntity>entity().productionEfficiency * 2.0f;
// While 0.5 efficiency currently reflects 100%, we do not need to multiply by any factor since powerProduction states the
// power which would be produced at 1.0 efficiency
return powerProduction * tile.<GeneratorEntity>entity().productionEfficiency;
}
@Override
@@ -57,12 +53,13 @@ public class PowerGenerator extends PowerDistributor{
public void setBars(){
super.setBars();
if(hasPower){
bars.add(new BlockBar(BarType.power, true, tile -> tile.<GeneratorEntity>entity().productionEfficiency / maxEfficiency));
bars.add(new BlockBar(BarType.power, true, tile -> tile.<GeneratorEntity>entity().productionEfficiency));
}
}
public static class GeneratorEntity extends TileEntity{
public float generateTime;
/** The efficiency of the producer. Currently, an efficiency of 0.5 means 100% */
public float productionEfficiency = 0.0f;
@Override

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.consumers;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.ucore.scene.ui.layout.Table;
import io.anuke.mindustry.entities.TileEntity;
@@ -86,10 +87,12 @@ public class ConsumePower extends Consume{
* @return The amount of power which is requested per tick.
*/
public float requestedPower(Block block, TileEntity entity){
// TODO Make the block not consume power on the following conditions, either here or in PowerGraph:
// - Other consumers are not valid, e.g. additional input items/liquids are missing
// - Buffer is full
return powerPerTick;
if(isBuffered){
// Stop requesting power once the buffer is full.
return MathUtils.isEqual(entity.power.satisfaction, 1.0f) ? 0.0f : powerPerTick;
}else{
return powerPerTick;
}
}