Skip to content

Modifying Data

After you have defined your packets, you can modify, cancel or build and send them manually.

You can modify packets by canceling them and sending a modified copy manually. We will use previously defined Set Held Item (clientbound) packet as an example.

[Subscribe]
public async ValueTask OnMessageReceived(MessageReceivedEvent @event, CancellationToken cancellationToken)
{
if (@event.Message is not SetHeldItemClientboundPacket packet)
return;
// Cancel the original packet
@event.Cancel();
// Modify the packet
packet.Slot = 1;
// Send the modified packet manually
await @event.Player.SendPacketAsync(packet, cancellationToken);
}