Fix multi-item boosters displaying multiple times (#10297)

This commit is contained in:
MEEPofFaith
2025-02-04 11:38:01 -08:00
committed by GitHub
parent 3dd53fd66e
commit 939506ffae
5 changed files with 22 additions and 19 deletions

View File

@@ -105,7 +105,7 @@ public class ForceProjector extends Block{
if(consItems && itemConsumer instanceof ConsumeItems coni){
stats.remove(Stat.booster);
stats.add(Stat.booster, StatValues.itemBoosters("+{0} " + StatUnit.shieldHealth.localized(), stats.timePeriod, phaseShieldBoost, phaseRadiusBoost, coni.items, this::consumesItem));
stats.add(Stat.booster, StatValues.itemBoosters("+{0} " + StatUnit.shieldHealth.localized(), stats.timePeriod, phaseShieldBoost, phaseRadiusBoost, coni.items));
stats.add(Stat.booster, StatValues.speedBoosters("", coolantConsumption, Float.MAX_VALUE, true, this::consumesLiquid));
}
}

View File

@@ -59,7 +59,7 @@ public class MendProjector extends Block{
stats.add(Stat.booster, StatValues.itemBoosters(
"{0}" + StatUnit.timesSpeed.localized(),
stats.timePeriod, (phaseBoost + healPercent) / healPercent, phaseRangeBoost,
cons.items, this::consumesItem)
cons.items)
);
}
}

View File

@@ -71,7 +71,7 @@ public class OverdriveProjector extends Block{
if(hasBoost && findConsumer(f -> f instanceof ConsumeItems) instanceof ConsumeItems items){
stats.remove(Stat.booster);
stats.add(Stat.booster, StatValues.itemBoosters("+{0}%", stats.timePeriod, speedBoostPhase * 100f, phaseRangeBoost, items.items, this::consumesItem));
stats.add(Stat.booster, StatValues.itemBoosters("+{0}%", stats.timePeriod, speedBoostPhase * 100f, phaseRangeBoost, items.items));
}
}

View File

@@ -97,7 +97,7 @@ public class RegenProjector extends Block{
stats.add(Stat.booster, StatValues.itemBoosters(
"{0}" + StatUnit.timesSpeed.localized(),
stats.timePeriod, optionalMultiplier, 0f,
cons.items, this::consumesItem)
cons.items)
);
}
}

View File

@@ -484,35 +484,38 @@ public class StatValues{
};
}
public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items, Boolf<Item> filter){
public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items){
return table -> {
table.row();
table.table(c -> {
for(Item item : content.items()){
if(!filter.get(item)) continue;
c.table(Styles.grayPanel, b -> {
c.table(Styles.grayPanel, b -> {
b.table(it -> {
for(ItemStack stack : items){
if(timePeriod < 0){
b.add(displayItem(stack.item, stack.amount, true)).pad(20f).left();
it.add(displayItem(stack.item, stack.amount, true)).pad(10f).padLeft(15f).left();
}else{
b.add(displayItem(stack.item, stack.amount, timePeriod, true)).pad(20f).left();
it.add(displayItem(stack.item, stack.amount, timePeriod, true)).pad(10f).padLeft(15f).left();
}
if(items.length > 1) b.row();
it.row();
}
}).left();
b.table(bt -> {
bt.right().defaults().padRight(3).left();
if(rangeBoost != 0) bt.add("[lightgray]+[stat]" + Strings.autoFixed(rangeBoost / tilesize, 2) + "[lightgray] " + StatUnit.blocks.localized()).row();
if(speedBoost != 0) bt.add("[lightgray]" + unit.replace("{0}", "[stat]" + Strings.autoFixed(speedBoost, 2) + "[lightgray]"));
}).right().grow().pad(10f).padRight(15f);
}).growX().pad(5).padBottom(-5).row();
}
b.table(bt -> {
bt.right().defaults().padRight(3).left();
if(rangeBoost != 0) bt.add("[lightgray]+[stat]" + Strings.autoFixed(rangeBoost / tilesize, 2) + "[lightgray] " + StatUnit.blocks.localized()).row();
if(speedBoost != 0) bt.add("[lightgray]" + unit.replace("{0}", "[stat]" + Strings.autoFixed(speedBoost, 2) + "[lightgray]"));
}).right().top().grow().pad(10f).padRight(15f);
}).growX().pad(5).padBottom(-5).row();
}).growX().colspan(table.getColumns());
table.row();
};
}
/** @deprecated Filter is no longer used. */
public static StatValue itemBoosters(String unit, float timePeriod, float speedBoost, float rangeBoost, ItemStack[] items, Boolf<Item> filter){
return itemBoosters(unit, timePeriod, speedBoost, rangeBoost, items);
}
public static StatValue weapons(UnitType unit, Seq<Weapon> weapons){
return table -> {
table.row();