use of net.silentchaos512.gear.network.RecalculateStatsPacket 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.network.RecalculateStatsPacket in project Silent-Gear by SilentChaos512.
the class RecalculateStatsPacket method decode.
public static RecalculateStatsPacket decode(FriendlyByteBuf buffer) {
int slot = buffer.readVarInt();
ItemStat stat = ItemStats.byName(buffer.readResourceLocation());
return new RecalculateStatsPacket(slot, Objects.requireNonNull(stat));
}
Aggregations