Search in sources :

Example 6 with ItemStat

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));
    }
}
Also used : ItemStat(net.silentchaos512.gear.api.stats.ItemStat) IItemStat(net.silentchaos512.gear.api.stats.IItemStat)

Example 7 with ItemStat

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);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color)

Example 8 with ItemStat

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);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color)

Example 9 with ItemStat

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);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color)

Example 10 with ItemStat

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;
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) JsonParseException(com.google.gson.JsonParseException) JsonObject(com.google.gson.JsonObject) java.util(java.util) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) MultimapBuilder(com.google.common.collect.MultimapBuilder) Multiset(com.google.common.collect.Multiset) Multimap(com.google.common.collect.Multimap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) MutableComponent(net.minecraft.network.chat.MutableComponent) JsonElement(com.google.gson.JsonElement) GearType(net.silentchaos512.gear.api.item.GearType) JsonArray(com.google.gson.JsonArray) TextComponent(net.minecraft.network.chat.TextComponent) GsonHelper(net.minecraft.util.GsonHelper) Entry(java.util.Map.Entry) IGearPart(net.silentchaos512.gear.api.part.IGearPart) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MutableComponent(net.minecraft.network.chat.MutableComponent)

Aggregations

ItemStat (net.silentchaos512.gear.api.stats.ItemStat)16 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 GearType (net.silentchaos512.gear.api.item.GearType)9 Color (net.silentchaos512.utils.Color)9 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)8 TextComponent (net.minecraft.network.chat.TextComponent)7 Component (net.minecraft.network.chat.Component)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5 Nullable (javax.annotation.Nullable)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 ItemStack (net.minecraft.world.item.ItemStack)4 IItemStat (net.silentchaos512.gear.api.stats.IItemStat)4 JsonObject (com.google.gson.JsonObject)3 JsonParseException (com.google.gson.JsonParseException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 GsonHelper (net.minecraft.util.GsonHelper)3 PartType (net.silentchaos512.gear.api.part.PartType)3