User Tools

Site Tools


tutorial:networking

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:networking [2023/04/16 01:01] – Make sure to show how to make the ID fxtutorial:networking [2023/04/16 01:03] fx
Line 79: Line 79:
  
 Next, we need to send the packet to the game client. First, you need to define an ''Identifier'' used to identify your packet. For this example our Identifier will be ''wiki_example:highlight_block''. In order to send the packet to the game client, you need to specify which player's game client you want the packet to be received by. Since the action is occurring on the logical server, we may upcast the ''player'' to a ''ServerPlayerEntity''. Next, we need to send the packet to the game client. First, you need to define an ''Identifier'' used to identify your packet. For this example our Identifier will be ''wiki_example:highlight_block''. In order to send the packet to the game client, you need to specify which player's game client you want the packet to be received by. Since the action is occurring on the logical server, we may upcast the ''player'' to a ''ServerPlayerEntity''.
 +<code java>
 +public class TutorialNetworkingConstants {
 +    // Save the id of the packet so we can reference it later
 +    public static final Identifier HIGHLIGHT_PACKET_ID = new Identifier("wiki_example", "highlight");
 +}
 +</code>
  
 To send the packet to the player, we will use some of the methods inside of ''ServerPlayNetworking''. We will use the following method inside of that class: To send the packet to the player, we will use some of the methods inside of ''ServerPlayNetworking''. We will use the following method inside of that class:
Line 90: Line 96:
  
 Since we are not writing any data to the packet, for now, we will send the packet with an empty payload. A buf with an empty payload may be created using ''PacketByteBufs.empty()''. Since we are not writing any data to the packet, for now, we will send the packet with an empty payload. A buf with an empty payload may be created using ''PacketByteBufs.empty()''.
- 
-(Note that the identifier we will put in a class accessible from both sides) 
- 
-<code java> 
-public class TutorialNetworkingConstants { 
-    // Save the id of the packet so we can reference it later 
-    public static final Identifier HIGHLIGHT_PACKET_ID = new Identifier("example", "highlight"); 
-} 
-</code> 
  
 <code java [enable_line_numbers="true", highlight_lines_extra="2"]> <code java [enable_line_numbers="true", highlight_lines_extra="2"]>
tutorial/networking.txt · Last modified: 2024/04/24 18:53 by skycatminepokie