Search in sources :

Example 1 with StatModifierMap

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

the class StatModifierMap method read.

public static StatModifierMap read(FriendlyByteBuf buffer) {
    StatModifierMap map = new StatModifierMap();
    int count = buffer.readVarInt();
    for (int i = 0; i < count; ++i) {
        StatGearKey key = StatGearKey.read(buffer);
        StatInstance instance = StatInstance.read(key, buffer);
        map.put(key, instance);
    }
    return map;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 2 with StatModifierMap

use of net.silentchaos512.gear.api.stats.StatModifierMap 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;
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 3 with StatModifierMap

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

the class MaterialBuilder method stat.

public MaterialBuilder stat(PartType partType, IItemStat stat, GearType gearType, float value, StatInstance.Operation operation) {
    StatGearKey key = StatGearKey.of(stat, gearType);
    StatInstance mod = StatInstance.of(value, operation, key);
    StatModifierMap map = stats.computeIfAbsent(partType, pt -> new StatModifierMap());
    map.put(stat, gearType, mod);
    return this;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 4 with StatModifierMap

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

the class StatModifierMap method deserialize.

public static StatModifierMap deserialize(JsonElement json) {
    StatModifierMap map = new StatModifierMap();
    if (json.isJsonObject()) {
        for (Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) {
            StatGearKey key = StatGearKey.read(entry.getKey());
            if (key != null) {
                JsonElement value = entry.getValue();
                if (value.isJsonArray()) {
                    for (JsonElement je : value.getAsJsonArray()) {
                        StatInstance mod = StatInstance.read(key, je);
                        map.put(key, mod);
                    }
                } else {
                    map.put(key, StatInstance.read(key, value));
                }
            }
        }
    } else if (json.isJsonArray()) {
        for (JsonElement element : json.getAsJsonArray()) {
            JsonObject jsonObj = element.getAsJsonObject();
            StatGearKey key = StatGearKey.read(GsonHelper.getAsString(jsonObj, "name"));
            if (key != null) {
                map.put(key, StatInstance.read(key, element));
            }
        }
    } else {
        throw new JsonParseException("Expected object or array");
    }
    return map;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 5 with StatModifierMap

use of net.silentchaos512.gear.api.stats.StatModifierMap 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)

Aggregations

StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)6 GearType (net.silentchaos512.gear.api.item.GearType)3 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)2 PartDataList (net.silentchaos512.gear.api.part.PartDataList)2 PartData (net.silentchaos512.gear.gear.part.PartData)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ListTag (net.minecraft.nbt.ListTag)1 Component (net.minecraft.network.chat.Component)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ItemStack (net.minecraft.world.item.ItemStack)1 IPartData (net.silentchaos512.gear.api.part.IPartData)1 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)1 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)1 StatModifierMap (net.silentchaos512.gear.api.stats.StatModifierMap)1 ITrait (net.silentchaos512.gear.api.traits.ITrait)1 TraitActionContext (net.silentchaos512.gear.api.traits.TraitActionContext)1