tutorial:networking
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:networking [2024/06/10 11:45] – 1.20.5: general improvements l1ttle | tutorial:networking [2024/10/26 20:39] (current) – [How do I fix the crash?] double "be" fix skycatminepokie | ||
---|---|---|---|
Line 58: | Line 58: | ||
| Singleplayer (or LAN host) | Yes -> Full access | | Singleplayer (or LAN host) | Yes -> Full access | ||
- | It may seem complicated to have communication with the server in three different ways. However, you don't need to communicate in three different ways with the game client. Since all three connection types communicate with the game client using packets, you only need to communicate with the game client like you are always running on a dedicated server. Connection to a server over LAN or Singleplayer can be also be treated like the server is a remote dedicated server; so your game client cannot directly access the server instance. | + | It may seem complicated to have communication with the server in three different ways. However, you don't need to communicate in three different ways with the game client. Since all three connection types communicate with the game client using packets, you only need to communicate with the game client like you are always running on a dedicated server. Connection to a server over LAN or Singleplayer can also be treated like the server is a remote dedicated server; so your game client cannot directly access the server instance. |
===== An introduction to networking ===== | ===== An introduction to networking ===== | ||
Line 80: | Line 80: | ||
</ | </ | ||
- | Next, we need to send the packet to the game client. First, you need to define an '' | + | Next, we need to send the packet to the game client. First, you need to define an '' |
<code java> | <code java> | ||
public class TutorialNetworkingConstants { | public class TutorialNetworkingConstants { | ||
// Save the id of the packet so we can reference it later | // Save the id of the packet so we can reference it later | ||
- | public static final Identifier HIGHLIGHT_PACKET_ID = new Identifier(" | + | public static final Identifier HIGHLIGHT_PACKET_ID = Identifier.of("tutorial", " |
} | } | ||
</ | </ | ||
Line 220: | Line 220: | ||
===== Networking in 1.20.5 ===== | ===== Networking in 1.20.5 ===== | ||
- | Since 1.20.5, the logic of networking has been totally rewritten. In 1.20.5, RegistryByteBuf is now used in PLAY-phase networking and you have to define a custom '' | + | Since 1.20.5, the logic of networking has been totally rewritten. In 1.20.5, |
<code java> | <code java> | ||
Line 243: | Line 243: | ||
And then, register the receiver like this: | And then, register the receiver like this: | ||
<code java> | <code java> | ||
+ | // NOTE: PayloadTypeRegistry has 2 functions: | ||
+ | // - playS2C is for server -> client communication | ||
+ | // - playC2S is for client -> server communication | ||
+ | |||
// In your common initializer method | // In your common initializer method | ||
PayloadTypeRegistry.playS2C().register(BlockHighlightPayload.ID, | PayloadTypeRegistry.playS2C().register(BlockHighlightPayload.ID, |
tutorial/networking.1718019912.txt.gz · Last modified: 2024/06/10 11:45 by l1ttle