Skip to content

Commit

Permalink
Multiple fluids bars + better bar customization
Browse files Browse the repository at this point in the history
  • Loading branch information
JojoFR1 committed May 18, 2024
1 parent 29b9b2e commit 0cb7147
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions lib/src/multicraft/MultiCrafter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import arc.scene.ui.layout.Cell;
import arc.scene.ui.layout.Table;
import arc.struct.*;
import arc.struct.EnumSet;
import arc.util.*;
import arc.util.io.Reads;
import arc.util.io.Writes;
import mindustry.Vars;
import mindustry.content.Fx;
import mindustry.content.*;
import mindustry.core.*;
import mindustry.entities.Effect;
import mindustry.entities.units.BuildPlan;
import mindustry.gen.Building;
Expand Down Expand Up @@ -272,13 +272,13 @@ public void updateTile() {
} else if (craftingTime >= craftTimeNeed)
craft();

updateBars();
dumpOutputs();
updateBars();
}

public void updateBars() {
barMap.clear();
setBars();
setBars(this);
}

@Override
Expand Down Expand Up @@ -637,10 +637,56 @@ protected void buildIOEntry(Table table, Recipe recipe, boolean isInput) {
}

@Override
public void setBars() {
super.setBars();
public void setBars() {}

public void setBars(MultiCrafterBuild build) {
addBar("health", entity -> new Bar("stat.health", Pal.health, entity::healthf).blink(Color.white));

if(consPower != null){
boolean buffered = consPower.buffered;
float capacity = consPower.capacity;

addBar("power", entity -> new Bar(
() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "<ERROR>" : UI.formatAmount((int)(entity.power.status * capacity))) :
Core.bundle.get("bar.power"),
() -> Pal.powerBar,
() -> Mathf.zero(consPower.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status)
);
}

if(hasItems && configurable){
addBar("items", entity -> new Bar(
() -> Core.bundle.format("bar.items", entity.items.total()),
() -> Pal.items,
() -> (float)entity.items.total() / itemCapacity)
);
}

if(unitCapModifier != 0){
stats.add(Stat.maxUnits, (unitCapModifier < 0 ? "-" : "+") + Math.abs(unitCapModifier));
}

//liquids added last
if(hasLiquids) {
boolean added = false;
for (Consume consumer : consumers) {
if (consumer instanceof ConsumeFluidDynamic) {
ConsumeFluidDynamic liq = (ConsumeFluidDynamic) consumer;
added = true;

for (LiquidStack stack : liq.fluids.get(build)) {
addLiquidBar(stack.liquid);
}
}
}

//nothing was added, so it's safe to add a dynamic liquid bar (probably?)
if (!added) {
addLiquidBar(build.liquids.current());
}
}

if (hasPower)
if (hasPower)
addBar("power", (MultiCrafterBuild b) -> new Bar(
b.getCurRecipe().isOutputPower() ? Core.bundle.format("bar.poweroutput", Strings.fixed(b.getPowerProduction() * 60f * b.timeScale(), 1)) : "bar.power",
Pal.powerBar,
Expand Down

1 comment on commit 0cb7147

@overdramaticpanromantic

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woohoo!

Please sign in to comment.