mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-19 08:47:29 +07:00
Fixed ConsumeGenerator 'kickstarting'
This commit is contained in:
parent
c8fb0c2e76
commit
f89f460b47
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user