Search in sources :

Example 16 with ItemStat

use of net.silentchaos512.gear.api.stats.ItemStat in project SilentGems by SilentChaos512.

the class ToolPartTip method getStatModifier.

@Override
public ItemStatModifier getStatModifier(ItemStat stat, EnumMaterialGrade grade) {
    float val = stats.getStat(stat);
    Operation op = ItemStatModifier.Operation.ADD;
    if (stat == CommonItemStats.ATTACK_SPEED)
        val -= 1f;
    else if (stat == CommonItemStats.HARVEST_LEVEL)
        op = ItemStatModifier.Operation.MAX;
    return new ItemStatModifier(getUnlocalizedName(), val, op);
}
Also used : ItemStatModifier(net.silentchaos512.gems.api.stats.ItemStatModifier) Operation(net.silentchaos512.gems.api.stats.ItemStatModifier.Operation)

Example 17 with ItemStat

use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.

the class StatInstance method formatMul2.

private MutableComponent formatMul2(ItemStat stat, @Nonnegative int decimalPlaces, boolean addColor) {
    String format = "%s" + ("%." + decimalPlaces + "f");
    float val = 1f + this.value;
    Color color = getFormattedColor(val, 1f, addColor);
    String text = trimNumber(String.format(format, "x", val));
    return TextUtil.withColor(new TextComponent(text), color);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color)

Example 18 with ItemStat

use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.

the class AbstractMaterial method isCraftingAllowed.

@Override
public boolean isCraftingAllowed(IMaterialInstance material, PartType partType, GearType gearType, @Nullable Container inventory) {
    if (isGearTypeBlacklisted(gearType) || !allowedInPart(material, partType)) {
        return false;
    }
    if (stats.containsKey(partType) || (getParent() != null && getParent().isCraftingAllowed(material, partType, gearType, inventory))) {
        if (partType == PartType.MAIN) {
            ItemStat stat = gearType.getDurabilityStat();
            StatGearKey key = StatGearKey.of(stat, gearType);
            return !getStatModifiers(material, partType, key).isEmpty() && getStatUnclamped(material, partType, key, ItemStack.EMPTY) > 0;
        }
        return true;
    }
    return false;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 19 with ItemStat

use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.

the class StatsCommand method runInfo.

private static int runInfo(CommandContext<CommandSourceStack> context, ServerPlayer player) {
    ItemStack stack = player.getMainHandItem();
    if (!GearHelper.isGear(stack)) {
        context.getSource().sendFailure(TextUtil.translate("command", "invalidItemType", stack.getHoverName()));
        return 0;
    }
    context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.header", player.getName(), stack.getHoverName()).withStyle(ChatFormatting.BOLD), true);
    ICoreItem item = (ICoreItem) stack.getItem();
    PartDataList parts = GearData.getConstructionParts(stack);
    StatModifierMap stats = GearData.getStatModifiers(stack, item, parts);
    for (ItemStat stat : ItemStats.allStatsOrderedExcluding((item).getExcludedStats(stack))) {
        StatGearKey key = StatGearKey.of(stat, item.getGearType());
        Collection<StatInstance> mods = stats.get(key);
        if (!mods.isEmpty()) {
            Component name = TextUtil.withColor(stat.getDisplayName(), stat.getNameColor());
            Component modsText = StatModifierMap.formatText(mods, stat, 5, true);
            float statValue = stat.compute(0f, true, item.getGearType(), mods);
            Component valueText = TextUtil.withColor(StatInstance.of(statValue, StatInstance.Operation.AVG, key).getFormattedText(stat, 5, false), ChatFormatting.YELLOW);
            context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.format", name, modsText, valueText), true);
            for (PartData part : parts) {
                Collection<StatInstance> partMods = part.getStatModifiers(key, stack);
                if (!partMods.isEmpty()) {
                    Component partName = part.getDisplayName(stack);
                    Component partModsText = StatModifierMap.formatText(partMods, stat, 5, true);
                    context.getSource().sendSuccess(TextUtil.translate("command", "stats.info.formatPart", partName, partModsText), true);
                }
            }
        }
    }
    return 1;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) StatModifierMap(net.silentchaos512.gear.api.stats.StatModifierMap) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 20 with ItemStat

use of net.silentchaos512.gear.api.stats.ItemStat in project Silent-Gear by SilentChaos512.

the class GearData method printStatsForDebugging.

private static void printStatsForDebugging(ItemStack stack, StatModifierMap stats, @Nullable Map<ItemStat, Float> oldStats) {
    // Prints stats that have changed for debugging purposes
    if (oldStats != null && SilentGear.LOGGER.isDebugEnabled()) {
        GearType gearType = GearHelper.getType(stack);
        Map<ItemStat, Float> newStats = getCurrentStatsForDebugging(stack);
        assert newStats != null;
        for (ItemStat stat : stats.getStats()) {
            float oldValue = oldStats.get(stat);
            float newValue = newStats.get(stat);
            float change = newValue - oldValue;
            SilentGear.LOGGER.debug(" - {}: {} -> {} ({}) - mods: [{}]", stat.getDisplayName().getString(), oldValue, newValue, change < 0 ? change : "+" + change, StatModifierMap.formatText(stats.get(stat, gearType), stat, 5).getString());
        }
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType)

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