package com.thebrokenrail.sorcerycraft.packet; import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.network.PacketContext; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; public class UpdateKnownSpellsS2CPacket { public static void handle(PacketContext context, PacketByteBuf bytes) { CompoundTag tag = bytes.readCompoundTag(); if (context.getPlayer() != null) { SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer(); spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag)); } } public static void send(ServerPlayerEntity player, CompoundTag tag) { PacketByteBuf bytes = new PacketByteBuf(Unpooled.buffer()); bytes.writeCompoundTag(tag); player.networkHandler.sendPacket(new CustomPayloadS2CPacket(new Identifier(SorceryCraft.NAMESPACE, "update_known_spells"), bytes)); } }