Added support for buffered power consumers
This commit is contained in:
@@ -28,6 +28,7 @@ public abstract class BaseBlock extends MappableContent{
|
||||
public boolean consumesPower;
|
||||
public boolean outputsPower;
|
||||
|
||||
public boolean bufferedPowerConsumer = false;
|
||||
public float basePowerUse = 0;
|
||||
|
||||
public int itemCapacity;
|
||||
|
||||
@@ -330,7 +330,10 @@ public class Block extends BaseBlock {
|
||||
|
||||
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(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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ public class PowerGraph{
|
||||
|
||||
float powerNeeded = 0f;
|
||||
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;
|
||||
@@ -64,9 +68,13 @@ public class PowerGraph{
|
||||
powerProduced += accumulatorUsed;
|
||||
}
|
||||
|
||||
float powerSatisfaction = Math.max(1, powerProduced / powerNeeded);
|
||||
float powerSatisfaction = Math.min(1, powerProduced / powerNeeded);
|
||||
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){
|
||||
|
||||
Reference in New Issue
Block a user