Search in sources :

Example 16 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey 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 17 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey 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 18 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey in project Silent-Gear by SilentChaos512.

the class CraftedMaterial method getStatKeys.

@Override
public Collection<StatGearKey> getStatKeys(IMaterialInstance material, PartType type) {
    Collection<StatGearKey> ret = new LinkedHashSet<>(super.getStatKeys(material, type));
    IMaterialInstance base = getBaseMaterial(material);
    ret.addAll(base.getStatKeys(type));
    return ret;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 19 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey in project Silent-Gear by SilentChaos512.

the class MaterialInstance method getEnchantmentModifiedStats.

@Deprecated
private void getEnchantmentModifiedStats(List<StatInstance> mods, StatGearKey key) {
    if (key.getStat() == ItemStats.CHARGEABILITY) {
        return;
    }
    // Search for materials that stats
    for (Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.getEnchantments(this.item).entrySet()) {
        Enchantment enchantment = entry.getKey();
        Integer level = entry.getValue();
        if (enchantment instanceof IStatModifierEnchantment) {
            IStatModifierEnchantment statModifierEnchantment = (IStatModifierEnchantment) enchantment;
            ChargedProperties charge = new ChargedProperties(level, getChargeability());
            // Replace modifiers with updated ones (if provided)
            for (int i = 0; i < mods.size(); i++) {
                StatInstance mod = mods.get(i);
                StatInstance newMod = statModifierEnchantment.modifyStat(key, mod, charge);
                if (newMod != null) {
                    mods.remove(i);
                    mods.add(i, newMod);
                }
            }
        }
    }
}
Also used : ChargedProperties(net.silentchaos512.gear.api.stats.ChargedProperties) IStatModifierEnchantment(net.silentchaos512.gear.api.enchantment.IStatModifierEnchantment) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) Enchantment(net.minecraft.world.item.enchantment.Enchantment) IStatModifierEnchantment(net.silentchaos512.gear.api.enchantment.IStatModifierEnchantment)

Example 20 with StatGearKey

use of net.silentchaos512.gear.api.util.StatGearKey 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)16 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)12 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)8 GearType (net.silentchaos512.gear.api.item.GearType)6 Component (net.minecraft.network.chat.Component)4 ItemStack (net.minecraft.world.item.ItemStack)4 JsonObject (com.google.gson.JsonObject)3 JsonParseException (com.google.gson.JsonParseException)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 PartType (net.silentchaos512.gear.api.part.PartType)3 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)3 java.util (java.util)2 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 GsonHelper (net.minecraft.util.GsonHelper)2