use of net.silentchaos512.gear.api.stats.StatInstance 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;
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class TooltipHandler method getStatTooltipLine.
private static Optional<MutableComponent> getStatTooltipLine(ItemTooltipEvent event, PartType partType, ItemStat stat, Collection<StatInstance> modifiers) {
if (!modifiers.isEmpty()) {
StatInstance inst = stat.computeForDisplay(0, GearType.ALL, modifiers);
if (inst.shouldList(partType, stat, event.getFlags().isAdvanced())) {
boolean isZero = inst.getValue() == 0;
Color nameColor = isZero ? MC_DARK_GRAY : stat.getNameColor();
Color statColor = isZero ? MC_DARK_GRAY : Color.WHITE;
MutableComponent nameStr = TextUtil.withColor(stat.getDisplayName(), nameColor);
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), statColor);
// 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 TooltipHandler method getPartStatLines.
private static void getPartStatLines(ItemTooltipEvent event, ItemStack stack, PartData part) {
GearType gearType = getPartGearType(part);
TextListBuilder builder = new TextListBuilder();
List<ItemStat> relevantStats = new ArrayList<>(part.getGearType().getRelevantStats());
if (part.getGearType().isArmor() && relevantStats.contains(ItemStats.DURABILITY)) {
int index = relevantStats.indexOf(ItemStats.DURABILITY);
relevantStats.remove(ItemStats.DURABILITY);
relevantStats.add(index, ItemStats.ARMOR_DURABILITY);
}
for (ItemStat stat : relevantStats) {
Collection<StatInstance> modifiers = new ArrayList<>();
for (StatInstance mod : part.getStatModifiers(StatGearKey.of(stat, gearType), ItemStack.EMPTY)) {
if (mod.getOp() == StatInstance.Operation.AVG) {
float computed = stat.compute(Collections.singleton(mod));
modifiers.add(StatInstance.of(computed, StatInstance.Operation.AVG, mod.getKey()));
} else {
modifiers.add(mod);
}
}
getStatTooltipLine(event, part.getType(), stat, modifiers).ifPresent(builder::add);
}
event.getToolTip().addAll(builder.build());
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class IStatModProvider method getStatUnclamped.
default float getStatUnclamped(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(stat.getBaseValue(), false, key.getGearType(), mods);
}
use of net.silentchaos512.gear.api.stats.StatInstance in project Silent-Gear by SilentChaos512.
the class GearData method getStatModifiers.
public static StatModifierMap getStatModifiers(ItemStack stack, ICoreItem item, PartDataList parts) {
GearType gearType = item.getGearType();
StatModifierMap stats = new StatModifierMap();
for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(stack))) {
StatGearKey itemKey = StatGearKey.of(stat, gearType);
for (PartData part : parts) {
for (StatInstance mod : part.getStatModifiers(itemKey, stack)) {
StatInstance modCopy = StatInstance.of(mod.getValue(), mod.getOp(), itemKey);
stats.put(modCopy.getKey(), modCopy);
}
}
}
return stats;
}
Aggregations