Skip to content

Commit

Permalink
Fixed Anuken#9714
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Apr 6, 2024
1 parent 08c8ab0 commit 33f0111
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/src/mindustry/world/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,11 @@ public <T extends Building> ConsumePower consumePowerDynamic(Floatf<T> usage){
return consume(new ConsumePowerDynamic((Floatf<Building>)usage));
}

/** Creates a consumer that consumes a dynamic amount of power. */
public <T extends Building> ConsumePower consumePowerDynamic(float displayed, Floatf<T> usage){
return consume(new ConsumePowerDynamic(displayed, (Floatf<Building>)usage));
}

/**
* Creates a consumer which stores power.
* @param powerCapacity The maximum capacity in power units.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void drawPlanRegion(BuildPlan plan, Eachable<BuildPlan> list){
public void init(){
if(loadPowerDynamic){
basePowerUse = consPower != null ? consPower.usage : 0f;
consumePowerDynamic((PayloadLoaderBuild loader) -> loader.shouldConsume() ? (loader.hasBattery() && !loader.exporting ? maxPowerConsumption + basePowerUse : basePowerUse) : 0f);
consumePowerDynamic(basePowerUse, (PayloadLoaderBuild loader) -> loader.shouldConsume() ? (loader.hasBattery() && !loader.exporting ? maxPowerConsumption + basePowerUse : basePowerUse) : 0f);
}

super.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void updateTile(){
(liquids.current() == payload.build.liquids.current() || liquids.currentAmount() <= 0.2f)){
var liq = payload.build.liquids.current();
float remaining = liquidCapacity - liquids.currentAmount();
float flow = Math.min(Math.min(liquidsLoaded * delta(), remaining), payload.build.liquids.currentAmount());
float flow = Math.min(Math.min(liquidsLoaded * edelta(), remaining), payload.build.liquids.currentAmount());

liquids.add(liq, flow);
payload.build.liquids.remove(liq, flow);
Expand Down
2 changes: 1 addition & 1 deletion core/src/mindustry/world/blocks/units/UnitFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void setStats(){
}

ItemStack stack = plan.requirements[i];
req.add(new ItemDisplay(stack.item, stack.amount, false)).pad(5);
req.add(new ItemDisplay(stack.item, stack.amount, plan.time, true)).pad(5);
}
}).right().grow().pad(10f);
}else{
Expand Down
11 changes: 10 additions & 1 deletion core/src/mindustry/world/consumers/ConsumePowerDynamic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@
/** A power consumer that uses a dynamic amount of power. */
public class ConsumePowerDynamic extends ConsumePower{
private final Floatf<Building> usage;
private float displayedPowerUsage;

public ConsumePowerDynamic(Floatf<Building> usage){
super(0, 0, false);
this.usage = usage;
}

public ConsumePowerDynamic(float displayed, Floatf<Building> usage){
super(0, 0, false);
this.displayedPowerUsage = displayed;
this.usage = usage;
}

@Override
public float requestedPower(Building entity){
return usage.get(entity);
}

@Override
public void display(Stats stats){

if(displayedPowerUsage != 0f){
stats.add(Stat.powerUse, displayedPowerUsage * 60f, StatUnit.powerSecond);
}
}
}

0 comments on commit 33f0111

Please sign in to comment.