Added support for buffered power consumers

This commit is contained in:
Baltazár Radics
2018-11-18 23:47:03 +01:00
parent 377fb2329c
commit 6ba8a6a600
3 changed files with 17 additions and 5 deletions

View File

@@ -28,6 +28,7 @@ public abstract class BaseBlock extends MappableContent{
public boolean consumesPower; public boolean consumesPower;
public boolean outputsPower; public boolean outputsPower;
public boolean bufferedPowerConsumer = false;
public float basePowerUse = 0; public float basePowerUse = 0;
public int itemCapacity; public int itemCapacity;

View File

@@ -330,7 +330,10 @@ public class Block extends BaseBlock {
consumes.forEach(cons -> cons.display(stats)); consumes.forEach(cons -> cons.display(stats));
if(hasPower) stats.add(BlockStat.powerCapacity, powerCapacity, StatUnit.powerUnits); if(hasPower){
if(bufferedPowerConsumer) stats.add(BlockStat.powerUse, basePowerUse, StatUnit.powerUnits);
else stats.add(BlockStat.powerCapacity, basePowerUse, StatUnit.powerUnits);
}
if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits); if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits);
if(hasItems) stats.add(BlockStat.itemCapacity, itemCapacity, StatUnit.items); if(hasItems) stats.add(BlockStat.itemCapacity, itemCapacity, StatUnit.items);
} }
@@ -550,4 +553,4 @@ public class Block extends BaseBlock {
"entity.graph", tile.entity.power != null && tile.entity.power.graph != null ? tile.entity.power.graph.getID() : null "entity.graph", tile.entity.power != null && tile.entity.power.graph != null ? tile.entity.power.graph.getID() : null
); );
} }
} }

View File

@@ -45,7 +45,11 @@ public class PowerGraph{
float powerNeeded = 0f; float powerNeeded = 0f;
for(Tile consumer : consumers){ for(Tile consumer : consumers){
powerNeeded += consumer.block().basePowerUse + consumer.entity.power.extraUse; if(consumer.block().bufferedPowerConsumer){
powerNeeded += (1f - consumer.entity.power.satisfaction) * consumer.block().basePowerUse;
}else{
powerNeeded += consumer.block().basePowerUse + consumer.entity.power.extraUse;
}
} }
float totalAccumulator = 0f; float totalAccumulator = 0f;
@@ -64,9 +68,13 @@ public class PowerGraph{
powerProduced += accumulatorUsed; powerProduced += accumulatorUsed;
} }
float powerSatisfaction = Math.max(1, powerProduced / powerNeeded); float powerSatisfaction = Math.min(1, powerProduced / powerNeeded);
for(Tile consumer : producers){ for(Tile consumer : producers){
consumer.power.satisfaction = powerSatisfaction; if(consumer.block().bufferedPowerConsumer){
consumer.power.satisfaction += (1 - consumer.power.satisfaction) * powerSatisfaction;
}else{
consumer.power.satisfaction = powerSatisfaction;
}
} }
if(powerProduced > powerNeeded){ if(powerProduced > powerNeeded){