use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class TooltipHandler method getMaterialStatModLines.
private static void getMaterialStatModLines(ItemTooltipEvent event, PartType partType, MaterialInstance material, TextListBuilder builder, ItemStat stat) {
Collection<StatInstance> modsAll = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
Optional<MutableComponent> head = getStatTooltipLine(event, partType, stat, modsAll);
builder.add(head.orElseGet(() -> TextUtil.withColor(stat.getDisplayName(), stat.getNameColor())));
builder.indent();
int subCount = 0;
List<StatGearKey> keysForStat = material.get().getStatKeys(material, partType).stream().filter(key -> key.getStat().equals(stat)).collect(Collectors.toList());
for (StatGearKey key : keysForStat) {
if (key.getGearType() != GearType.ALL) {
ItemStat stat1 = ItemStats.get(key.getStat());
if (stat1 != null) {
Collection<StatInstance> mods = material.getStatModifiers(partType, key);
Optional<MutableComponent> line = getSubStatTooltipLine(event, partType, stat1, key.getGearType(), mods);
if (line.isPresent()) {
builder.add(line.get());
++subCount;
}
}
}
}
if (subCount == 0 && !head.isPresent()) {
builder.removeLast();
}
builder.unindent();
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class TooltipHandler method getSubStatTooltipLine.
private static Optional<MutableComponent> getSubStatTooltipLine(ItemTooltipEvent event, PartType partType, ItemStat stat, GearType gearType, Collection<StatInstance> modifiers) {
if (!modifiers.isEmpty()) {
StatInstance inst = stat.computeForDisplay(0, gearType, modifiers);
if (inst.shouldList(partType, stat, event.getFlags().isAdvanced())) {
boolean isZero = inst.getValue() == 0;
Color color = isZero ? MC_DARK_GRAY : Color.WHITE;
MutableComponent nameStr = TextUtil.withColor(gearType.getDisplayName().copy(), color);
int decimalPlaces = stat.isDisplayAsInt() && inst.getOp() != StatInstance.Operation.MUL1 && inst.getOp() != StatInstance.Operation.MUL2 ? 0 : 2;
MutableComponent statListText = TextUtil.withColor(StatModifierMap.formatText(modifiers, stat, decimalPlaces), color);
// Harvest level hints
MutableComponent textWithAdditions = stat == ItemStats.HARVEST_LEVEL && modifiers.size() == 1 ? harvestLevelWithHint(statListText, inst.getValue()) : statListText;
return Optional.of(new TranslatableComponent("stat.silentgear.displayFormat", nameStr, textWithAdditions));
}
}
return Optional.empty();
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class IStatModProvider method getStat.
default float getStat(D instance, PartType partType, StatGearKey key, ItemStack gear) {
ItemStat stat = ItemStats.get(key.getStat());
if (stat == null)
return key.getStat().getDefaultValue();
Collection<StatInstance> mods = getStatModifiers(instance, partType, key, gear);
return stat.compute(mods);
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class StatGearKey method read.
@Nullable
public static StatGearKey read(String key) {
String[] parts = key.split("/");
if (parts.length > 2) {
throw new JsonParseException("invalid key: " + key);
}
ItemStat stat = ItemStats.getRegistry().getValue(SilentGear.getIdWithDefaultNamespace(parts[0]));
if (stat == null) {
return null;
}
GearType gearType;
if (parts.length > 1) {
gearType = GearType.get(parts[1]);
if (gearType.isInvalid()) {
throw new JsonParseException("Unknown gear type: " + parts[1]);
}
} else {
gearType = GearType.ALL;
}
return new StatGearKey(stat, gearType);
}
Aggregations