Parse singular consumes (#8466)

* Parse singular `Consume`s

* Proper coolant parsing

* Temporary manual update of ClassMap

Does not include all consume types.

I don't know what gradle command to run to update `ClassMap`. I've tried `tools:updateScripts` but that just cleared everything.
This commit is contained in:
MEEPofFaith
2023-04-02 16:53:19 -07:00
committed by GitHub
parent fa02d8d280
commit b322b1165f
4 changed files with 23 additions and 0 deletions

View File

@@ -459,6 +459,8 @@ public class ClassMap{
classes.put("DrawTurret", mindustry.world.draw.DrawTurret.class);
classes.put("DrawWarmupRegion", mindustry.world.draw.DrawWarmupRegion.class);
classes.put("DrawWeave", mindustry.world.draw.DrawWeave.class);
classes.put("ConsumeCoolant", mindustry.world.consumers.ConsumeCoolant.class);
classes.put("ConsumeLiquidFlammable", mindustry.world.consumers.ConsumeLiquidFlammable.class);
classes.put("Block", mindustry.world.Block.class);
}
}

View File

@@ -296,6 +296,20 @@ public class ContentParser{
weapon.name = currentMod.name + "-" + weapon.name;
return weapon;
});
put(Consume.class, (type, data) -> {
var oc = resolve(data.getString("type", ""), Consume.class);
data.remove("type");
var consume = make(oc);
readFields(consume, data);
return consume;
});
put(ConsumeLiquidBase.class, (type, data) -> {
var oc = resolve(data.getString("type", ""), ConsumeLiquidBase.class);
data.remove("type");
var consume = make(oc);
readFields(consume, data);
return consume;
});
}};
/** Stores things that need to be parsed fully, e.g. reading fields of content.
* This is done to accommodate binding of content names first.*/

View File

@@ -925,6 +925,10 @@ public class Block extends UnlockableContent implements Senseable{
return consumers.length == 0 ? (T)consumeBuilder.find(filter) : (T)Structs.find(consumers, filter);
}
public boolean hasConsumer(Consume cons){
return consumeBuilder.contains(cons);
}
public void removeConsumer(Consume cons){
if(consumers.length > 0){
throw new IllegalStateException("You can only remove consumers before init(). After init(), all consumers have already been initialized.");

View File

@@ -51,6 +51,9 @@ public class BaseTurret extends Block{
coolant.update = false;
coolant.booster = true;
coolant.optional = true;
//json parsing does not add to consumes
if(!hasConsumer(coolant)) consume(coolant);
}
placeOverlapRange = Math.max(placeOverlapRange, range + placeOverlapMargin);