use of net.silentchaos512.gear.api.stats.ItemStat 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.ItemStat 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.ItemStat 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.ItemStat 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;
}
use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.
the class RecalculateStatsPacket method decode.
public static RecalculateStatsPacket decode(FriendlyByteBuf buffer) {
int slot = buffer.readVarInt();
ItemStat stat = ItemStats.byName(buffer.readResourceLocation());
return new RecalculateStatsPacket(slot, Objects.requireNonNull(stat));
}
Aggregations