use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class MaterialsCommand method makeTsvLine.
private static String makeTsvLine(MaterialInstance material, PartType partType) {
StringBuilder builder = new StringBuilder();
appendTsv(builder, material.get().getPackName());
appendTsv(builder, material.getDisplayName(partType).getString());
int tier = material.getTier(partType);
// appendTsv(builder, partType.getDisplayName(tier).getFormattedText());
appendTsv(builder, partType.getDisplayName(0).getString());
appendTsv(builder, material.getId().toString());
appendTsv(builder, getParentId(material.get()));
// Traits
appendTsv(builder, material.getTraits(partType).stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
appendTsv(builder, tier);
// Stats
for (ItemStat stat : ItemStats.allStatsOrdered()) {
Collection<StatInstance> statModifiers = material.getStatModifiers(partType, StatGearKey.of(stat, GearType.ALL));
appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
}
return builder.toString();
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class PartsCommand method partToTsvLine.
private static String partToTsvLine(IGearPart part) {
StringBuilder builder = new StringBuilder();
PartData partData = PartData.of(part);
appendTsv(builder, part.getDisplayName(partData, ItemStack.EMPTY).getString());
appendTsv(builder, part.getId().toString());
appendTsv(builder, part.getType().getName());
appendTsv(builder, partData.getTier());
// Stats
for (ItemStat stat : ItemStats.allStatsOrdered()) {
Collection<StatInstance> statModifiers = partData.getStatModifiers(StatGearKey.of(stat, GearType.ALL), ItemStack.EMPTY);
appendTsv(builder, FORMAT_CODES.matcher(StatModifierMap.formatText(statModifiers, stat, 5).getString()).replaceAll(""));
}
// Traits
appendTsv(builder, partData.getTraits().stream().map(t -> t.getTrait().getDisplayName(t.getLevel()).getString()).collect(Collectors.joining(", ")));
return builder.toString();
}
use of net.silentchaos512.gear.api.stats.StatInstance 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.StatInstance 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.StatInstance 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);
}
Aggregations