-
Notifications
You must be signed in to change notification settings - Fork 0
docs(astro): π updated deprecated API usage in code examples #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a258e8e
2ab1757
0ab5d43
b50bfc3
20349b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,17 @@ public class SetHeldItemClientboundPacket : IMinecraftClientboundPacket<SetHeldI | |
| ## Registering Packets | ||
| Before receiving or sending packets, you need to register them specifying packet ids for each game protocol version. | ||
| Packet registrations are made for each game phase, so you need to register them in the correct phase. Common phases are `Handshake`, `Login`, `Configuration` and `Play`. | ||
|
|
||
| In this example we are using Void predefined packet id mappings in `PacketIdDefinitions`. | ||
| ```csharp | ||
| [Subscribe] | ||
| public void OnPlayerJoinedServer(PlayerJoinedServerEvent @event) | ||
| { | ||
| @event.Player.RegisterPacket<SetHeldItemClientboundPacket>(PacketIdDefinitions.ClientboundSetHeldItem); | ||
| } | ||
| ``` | ||
|
|
||
| You can also define your own mappings for packets you'd like to work with: | ||
| ```csharp | ||
| [Subscribe] | ||
| public void OnPlayerJoinedServer(PlayerJoinedServerEvent @event) | ||
|
|
@@ -132,7 +143,7 @@ await player.SendPacketAsync(new SetHeldItemClientboundPacket { Slot = slot }, c | |
| ### Sending Packets to the Server | ||
| You can send packets to the server with `ILink.ServerChannel` instance. | ||
| ```csharp | ||
| await player.GetLink().ServerChannel.SendPacketAsync(new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
| await player.Link.ServerChannel.SendPacketAsync(new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
| ``` | ||
|
|
||
| ### Sending Packets to the [**`ILink`**](/docs/developing-plugins/network/links) | ||
|
|
@@ -143,12 +154,12 @@ You can send packets to the link with `ILink.SendPacketAsync` method. | |
| - If the packet has both interfaces, it will be sent only to the client. | ||
| - If the packet has neither interface, `InvalidOperationException` will be thrown. | ||
| ```csharp | ||
| await player.GetLink().SendPacketAsync(new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
| await player.Link.SendPacketAsync(new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
| ``` | ||
|
|
||
| When you want to explicitly send a packet to the server or client, `SendPacketAsync` has an overload that specifies the destination side. | ||
| ```csharp | ||
| await player.GetLink().SendPacketAsync(Side.Client, new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
| await player.Link.SendPacketAsync(Side.Client, new SetHeldItemClientboundPacket { Slot = slot }, cancellationToken); | ||
|
Comment on lines
+157
to
+162
|
||
| ``` | ||
|
|
||
| ## Complete Example | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IPlayer.Linkis nullable (it returnsILink?), so dereferencing it directly in the example can produce aNullReferenceExceptionand also shows a pattern that wonβt compile cleanly with nullable reference types enabled. Consider using the non-null link instance from the relevant event (when available) or explicitly guarding (e.g., assignplayer.Linkto a local variable and throw a clear exception if itβs null) before calling intoServerChannel.