use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatModifierTrait method readBuffer.
private static void readBuffer(StatModifierTrait trait, FriendlyByteBuf buffer) {
trait.mods.clear();
int count = buffer.readByte();
for (int i = 0; i < count; ++i) {
ItemStat stat = ItemStats.getRegistry().getValue(buffer.readResourceLocation());
trait.mods.put(stat, StatMod.read(buffer));
}
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatInstance method formatMul1.
private MutableComponent formatMul1(ItemStat stat, @Nonnegative int decimalPlaces, boolean addColor) {
int percent = Math.round(100 * this.value);
Color color = getFormattedColor(percent, 0f, addColor);
String text = trimNumber(String.format("%s%d%%", percent < 0 ? "" : "+", percent));
return TextUtil.withColor(new TextComponent(text), color);
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatInstance method formatAvg.
private MutableComponent formatAvg(ItemStat stat, @Nonnegative int decimalPlaces, boolean addColor) {
Color color = getFormattedColor(this.value, 0f, addColor);
String text;
if (stat.getDisplayFormat() == ItemStat.DisplayFormat.PERCENTAGE) {
text = Math.round(this.value * 100) + "%";
} else {
// v (or vx for multiplier stats like armor durability)
String format = "%s" + ("%." + decimalPlaces + "f") + "%s";
String ret = trimNumber(String.format(format, "", this.value, ""));
text = stat.getDisplayFormat() == ItemStat.DisplayFormat.MULTIPLIER ? ret + "x" : ret;
}
return TextUtil.withColor(new TextComponent(text), color);
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatInstance method formatAdd.
// region Private formatted text methods
private MutableComponent formatAdd(ItemStat stat, @Nonnegative int decimalPlaces, boolean addColor) {
String format = "%s" + ("%." + decimalPlaces + "f");
Color color = getFormattedColor(this.value, 0f, addColor);
String text = trimNumber(String.format(format, this.value < 0 ? "" : "+", this.value));
return TextUtil.withColor(new TextComponent(text), color);
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatModifierMap method formatText.
public static MutableComponent formatText(Collection<StatInstance> mods, ItemStat stat, int maxDecimalPlaces, boolean addModColors) {
if (mods.size() == 1) {
StatInstance inst = mods.iterator().next();
int decimalPlaces = inst.getPreferredDecimalPlaces(stat, maxDecimalPlaces);
return inst.getFormattedText(stat, decimalPlaces, addModColors);
}
// Sort modifiers by operation
MutableComponent result = new TextComponent("");
List<StatInstance> toSort = new ArrayList<>(mods);
toSort.sort(Comparator.comparing(inst -> inst.getOp().ordinal()));
for (StatInstance inst : toSort) {
if (!result.getSiblings().isEmpty()) {
result.append(", ");
}
result.append(inst.getFormattedText(stat, inst.getPreferredDecimalPlaces(stat, maxDecimalPlaces), addModColors));
}
return result;
}
Aggregations