From 33f01112cae7a85780c519675ec7fe41742190df Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 6 Apr 2024 18:20:45 -0400 Subject: [PATCH] Fixed #9714 --- core/src/mindustry/world/Block.java | 5 +++++ .../world/blocks/payloads/PayloadLoader.java | 2 +- .../world/blocks/payloads/PayloadUnloader.java | 2 +- .../src/mindustry/world/blocks/units/UnitFactory.java | 2 +- .../world/consumers/ConsumePowerDynamic.java | 11 ++++++++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 5dcf542400e0..2e9f291b7dd6 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -993,6 +993,11 @@ public ConsumePower consumePowerDynamic(Floatf usage){ return consume(new ConsumePowerDynamic((Floatf)usage)); } + /** Creates a consumer that consumes a dynamic amount of power. */ + public ConsumePower consumePowerDynamic(float displayed, Floatf usage){ + return consume(new ConsumePowerDynamic(displayed, (Floatf)usage)); + } + /** * Creates a consumer which stores power. * @param powerCapacity The maximum capacity in power units. diff --git a/core/src/mindustry/world/blocks/payloads/PayloadLoader.java b/core/src/mindustry/world/blocks/payloads/PayloadLoader.java index 301789e54b1e..d323c69feb86 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadLoader.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadLoader.java @@ -76,7 +76,7 @@ public void drawPlanRegion(BuildPlan plan, Eachable 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(); diff --git a/core/src/mindustry/world/blocks/payloads/PayloadUnloader.java b/core/src/mindustry/world/blocks/payloads/PayloadUnloader.java index fac5f083a1a9..205402fdd686 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadUnloader.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadUnloader.java @@ -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); diff --git a/core/src/mindustry/world/blocks/units/UnitFactory.java b/core/src/mindustry/world/blocks/units/UnitFactory.java index 7b98b80e2f58..b89d945c65fc 100644 --- a/core/src/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/mindustry/world/blocks/units/UnitFactory.java @@ -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{ diff --git a/core/src/mindustry/world/consumers/ConsumePowerDynamic.java b/core/src/mindustry/world/consumers/ConsumePowerDynamic.java index f444c7c66f02..fb40c0aaa9f0 100644 --- a/core/src/mindustry/world/consumers/ConsumePowerDynamic.java +++ b/core/src/mindustry/world/consumers/ConsumePowerDynamic.java @@ -7,12 +7,19 @@ /** A power consumer that uses a dynamic amount of power. */ public class ConsumePowerDynamic extends ConsumePower{ private final Floatf usage; + private float displayedPowerUsage; public ConsumePowerDynamic(Floatf usage){ super(0, 0, false); this.usage = usage; } + public ConsumePowerDynamic(float displayed, Floatf usage){ + super(0, 0, false); + this.displayedPowerUsage = displayed; + this.usage = usage; + } + @Override public float requestedPower(Building entity){ return usage.get(entity); @@ -20,6 +27,8 @@ public float requestedPower(Building entity){ @Override public void display(Stats stats){ - + if(displayedPowerUsage != 0f){ + stats.add(Stat.powerUse, displayedPowerUsage * 60f, StatUnit.powerSecond); + } } }