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();
}
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;
}
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;
}
Aggregations