From 91cc6edd6a5c7cfba23e33c64c12b1e4e4628b17 Mon Sep 17 00:00:00 2001 From: Shade Date: Thu, 21 Mar 2024 17:56:23 +0800 Subject: [PATCH 1/4] Added itemDurationMultipliers --- core/src/mindustry/world/blocks/power/ConsumeGenerator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index a3b29b4cfdbf..9e1491d9a334 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -3,6 +3,7 @@ import arc.*; import arc.graphics.*; import arc.math.*; +import arc.struct.ObjectFloatMap; import arc.util.*; import mindustry.content.*; import mindustry.entities.*; @@ -28,6 +29,8 @@ public class ConsumeGenerator extends PowerGenerator{ public @Nullable ConsumeItemFilter filterItem; public @Nullable ConsumeLiquidFilter filterLiquid; + /** Multiplies the itemDuration for a given item*/ + public ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); public ConsumeGenerator(String name){ super(name); @@ -122,7 +125,7 @@ public void updateTile(){ } //generation time always goes down, but only at the end so consumeTriggerValid doesn't assume fake items - generateTime -= delta() / itemDuration; + generateTime -= delta() / (itemDuration * itemDurationMultipliers.get(filterItem.getConsumed(this), 1)); } @Override From e29077826211fd6d7151495a9cba83ec45b35ecf Mon Sep 17 00:00:00 2001 From: Shade Date: Thu, 21 Mar 2024 21:16:14 +0800 Subject: [PATCH 2/4] Bugfix to Item Duration Duration issues when there is no items left, duration is set to 1, affecting while it's still "valid". --- .../mindustry/world/blocks/power/ConsumeGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index 9e1491d9a334..b67df765e3eb 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -29,7 +29,7 @@ public class ConsumeGenerator extends PowerGenerator{ public @Nullable ConsumeItemFilter filterItem; public @Nullable ConsumeLiquidFilter filterLiquid; - /** Multiplies the itemDuration for a given item*/ + /** Multiplies the itemDuration for a given item. */ public ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); public ConsumeGenerator(String name){ @@ -79,7 +79,7 @@ public void setStats(){ } public class ConsumeGeneratorBuild extends GeneratorBuild{ - public float warmup, totalTime, efficiencyMultiplier = 1f; + public float warmup, totalTime, efficiencyMultiplier, itemDurationMultiplier = 1f; @Override public void updateEfficiencyMultiplier(){ @@ -106,6 +106,9 @@ public void updateTile(){ generateEffect.at(x + Mathf.range(generateEffectRange), y + Mathf.range(generateEffectRange)); } + //make sure the multiplier doesn't change when there is nothing to consume while it's still running + itemDurationMultiplier = (hasItems && valid && filterItem.getConsumed(this) == null)? itemDurationMultiplier : itemDurationMultipliers.get(filterItem.getConsumed(this), 1); + //take in items periodically if(hasItems && valid && generateTime <= 0f){ consume(); @@ -125,7 +128,7 @@ public void updateTile(){ } //generation time always goes down, but only at the end so consumeTriggerValid doesn't assume fake items - generateTime -= delta() / (itemDuration * itemDurationMultipliers.get(filterItem.getConsumed(this), 1)); + generateTime -= delta() / (itemDuration * itemDurationMultiplier); } @Override From cf9091df895e5d71bee9e6292c2191ba73925158 Mon Sep 17 00:00:00 2001 From: Shade Date: Fri, 22 Mar 2024 00:18:10 +0800 Subject: [PATCH 3/4] Correct Null Checks --- .../mindustry/world/blocks/power/ConsumeGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index b67df765e3eb..7e70bd5c75e0 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -30,7 +30,7 @@ public class ConsumeGenerator extends PowerGenerator{ public @Nullable ConsumeItemFilter filterItem; public @Nullable ConsumeLiquidFilter filterLiquid; /** Multiplies the itemDuration for a given item. */ - public ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); + public @Nullable ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); public ConsumeGenerator(String name){ super(name); @@ -79,7 +79,8 @@ public void setStats(){ } public class ConsumeGeneratorBuild extends GeneratorBuild{ - public float warmup, totalTime, efficiencyMultiplier, itemDurationMultiplier = 1f; + public float warmup, totalTime, efficiencyMultiplier = 1f; + public float itemDurationMultiplier = 1; @Override public void updateEfficiencyMultiplier(){ @@ -107,7 +108,9 @@ public void updateTile(){ } //make sure the multiplier doesn't change when there is nothing to consume while it's still running - itemDurationMultiplier = (hasItems && valid && filterItem.getConsumed(this) == null)? itemDurationMultiplier : itemDurationMultipliers.get(filterItem.getConsumed(this), 1); + if(hasItems && filterItem != null && itemDurationMultipliers != null){ + itemDurationMultiplier = (valid && filterItem.getConsumed(this) == null)? itemDurationMultiplier : itemDurationMultipliers.get(filterItem.getConsumed(this), 1); + } //take in items periodically if(hasItems && valid && generateTime <= 0f){ From 1c111bce848dcedc1e5882fd4976f70aab97a43a Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:16:57 +0530 Subject: [PATCH 4/4] Fixes * itemDurationMultipliers cannot be null * cleanup --- .../mindustry/world/blocks/power/ConsumeGenerator.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index 7e70bd5c75e0..eecf378b7c6e 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -30,7 +30,7 @@ public class ConsumeGenerator extends PowerGenerator{ public @Nullable ConsumeItemFilter filterItem; public @Nullable ConsumeLiquidFilter filterLiquid; /** Multiplies the itemDuration for a given item. */ - public @Nullable ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); + public ObjectFloatMap itemDurationMultipliers = new ObjectFloatMap<>(); public ConsumeGenerator(String name){ super(name); @@ -79,8 +79,7 @@ public void setStats(){ } public class ConsumeGeneratorBuild extends GeneratorBuild{ - public float warmup, totalTime, efficiencyMultiplier = 1f; - public float itemDurationMultiplier = 1; + public float warmup, totalTime, efficiencyMultiplier = 1f, itemDurationMultiplier = 1; @Override public void updateEfficiencyMultiplier(){ @@ -108,8 +107,8 @@ public void updateTile(){ } //make sure the multiplier doesn't change when there is nothing to consume while it's still running - if(hasItems && filterItem != null && itemDurationMultipliers != null){ - itemDurationMultiplier = (valid && filterItem.getConsumed(this) == null)? itemDurationMultiplier : itemDurationMultipliers.get(filterItem.getConsumed(this), 1); + if(filterItem != null && valid && filterItem.getConsumed(this) != null){ + itemDurationMultiplier = itemDurationMultipliers.get(filterItem.getConsumed(this), 1); } //take in items periodically