diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index ce23b0e4e9..9efa9120d2 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -510,6 +510,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, public void created(){} + /** @return whether this block is currently "active" and should be consuming requirements. */ public boolean shouldConsume(){ return enabled; } @@ -518,6 +519,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, return true; } + /** @return whether this building is currently "burning" a trigger consumer (an item) - if true, valid() on those will return true. */ + public boolean consumeTriggerValid(){ + return false; + } + public float getPowerProduction(){ return 0f; } diff --git a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java index 464e8e1d08..4db25f5681 100644 --- a/core/src/mindustry/world/blocks/power/ConsumeGenerator.java +++ b/core/src/mindustry/world/blocks/power/ConsumeGenerator.java @@ -11,7 +11,6 @@ import mindustry.world.meta.*; /** * A generator that just takes in certain items or liquids. Basically SingleTypeGenerator, but not unreliable garbage. - * TODO at the moment, these generators require at least one item in their inventory to work, meaning they cannot be "kickstarted" with only one item. */ public class ConsumeGenerator extends PowerGenerator{ /** The time in number of ticks during which a single item will produce power. */ @@ -72,9 +71,6 @@ public class ConsumeGenerator extends PowerGenerator{ productionEfficiency = valid ? 1f : 0f; totalTime += warmup * Time.delta; - //generation time always goes down - generateTime -= Math.min(1f / itemDuration * delta(), generateTime); - //randomly produce the effect if(valid && Mathf.chanceDelta(effectChance)){ generateEffect.at(x + Mathf.range(generateEffectRange), y + Mathf.range(generateEffectRange)); @@ -82,7 +78,7 @@ public class ConsumeGenerator extends PowerGenerator{ //take in items periodically if(hasItems && valid && generateTime <= 0f && items.any()){ - cons.trigger(); + consume(); generateTime = 1f; } @@ -91,6 +87,14 @@ public class ConsumeGenerator extends PowerGenerator{ liquids.add(liquidOutput.liquid, added); dumpLiquid(liquidOutput.liquid); } + + //generation time always goes down, but only at the end so consumeTriggerValid doesn't assume fake items + generateTime -= Math.min(1f / itemDuration * delta(), generateTime); + } + + @Override + public boolean consumeTriggerValid(){ + return generateTime > 0; } @Override diff --git a/core/src/mindustry/world/consumers/ConsumeItemDynamic.java b/core/src/mindustry/world/consumers/ConsumeItemDynamic.java index 8dce26c0f8..b94d11d15c 100644 --- a/core/src/mindustry/world/consumers/ConsumeItemDynamic.java +++ b/core/src/mindustry/world/consumers/ConsumeItemDynamic.java @@ -54,6 +54,6 @@ public class ConsumeItemDynamic extends Consume{ @Override public boolean valid(Building build){ - return build.items != null && build.items.has(items.get(build)); + return build.consumeTriggerValid() || build.items.has(items.get(build)); } } diff --git a/core/src/mindustry/world/consumers/ConsumeItemFilter.java b/core/src/mindustry/world/consumers/ConsumeItemFilter.java index 7eb98ace27..d3db733117 100644 --- a/core/src/mindustry/world/consumers/ConsumeItemFilter.java +++ b/core/src/mindustry/world/consumers/ConsumeItemFilter.java @@ -53,9 +53,11 @@ public class ConsumeItemFilter extends Consume{ @Override public boolean valid(Building build){ + if(build.consumeTriggerValid()) return true; + for(int i = 0; i < content.items().size; i++){ Item item = content.item(i); - if(build.items != null && build.items.has(item) && this.filter.get(item)){ + if(this.filter.get(item) && build.items.has(item)){ return true; } } diff --git a/core/src/mindustry/world/consumers/ConsumeItems.java b/core/src/mindustry/world/consumers/ConsumeItems.java index d0c1226bfc..90f1c4fd85 100644 --- a/core/src/mindustry/world/consumers/ConsumeItems.java +++ b/core/src/mindustry/world/consumers/ConsumeItems.java @@ -52,7 +52,7 @@ public class ConsumeItems extends Consume{ @Override public boolean valid(Building build){ - return build.items != null && build.items.has(items); + return build.consumeTriggerValid() || build.items.has(items); } @Override