Search in sources :

Example 1 with IItemStat

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

the class GearData method getStat.

public static float getStat(ItemStack stack, IItemStat stat, boolean calculateIfMissing) {
    CompoundTag tags = getData(stack, NBT_ROOT_PROPERTIES).getCompound(NBT_STATS);
    String key = stat.getStatId().toString();
    if (tags.contains(key)) {
        return tags.getFloat(key);
    }
    if (calculateIfMissing) {
        // Stat is missing, notify server to recalculate
        Level level = SilentGear.PROXY.getClientLevel();
        if (level != null && GearHelper.isValidGear(stack) && ((ICoreItem) stack.getItem()).getRelevantStats(stack).contains(stat)) {
            SilentGear.LOGGER.debug("Sending recalculate stats packet for item with missing {} stat: {}", stat.getStatId(), stack.getHoverName().getString());
            Network.channel.sendToServer(new RecalculateStatsPacket(level, stack, stat));
            // Prevent the packet from being spammed...
            putStatInNbtIfMissing(stack, stat);
        }
    }
    return stat.getDefaultValue();
}
Also used : RecalculateStatsPacket(net.silentchaos512.gear.network.RecalculateStatsPacket) Level(net.minecraft.world.level.Level) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with IItemStat

use of net.silentchaos512.gear.api.stats.IItemStat 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 3 with IItemStat

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

the class PartBuilder method stat.

public PartBuilder stat(IItemStat stat, float value, StatInstance.Operation operation) {
    StatGearKey key = StatGearKey.of(stat, GearType.ALL);
    StatInstance mod = StatInstance.of(value, operation, key);
    this.stats.put(stat, GearType.ALL, mod);
    return this;
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Aggregations

StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)2 CompoundTag (net.minecraft.nbt.CompoundTag)1 Level (net.minecraft.world.level.Level)1 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)1 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)1 RecalculateStatsPacket (net.silentchaos512.gear.network.RecalculateStatsPacket)1