tutorial:networking
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:networking [2021/01/20 13:51] – ytg1234 | tutorial:networking [2022/01/28 06:28] – [How do I fix the crash?] fix type solidblock | ||
---|---|---|---|
Line 51: | Line 51: | ||
[[Minecraft' | [[Minecraft' | ||
- | The diagram above shows that the game client and dedicated server | + | The diagram above shows that the game client and dedicated server |
^ Connection Type ^ Access to game client | ^ Connection Type ^ Access to game client | ||
Line 95: | Line 95: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
.... | .... | ||
- | ServerPlayNetworking.send((ServerPlayerEntity) user, ModNetworkingConstants.HIGHLIGHT_PACKET_ID, | + | ServerPlayNetworking.send((ServerPlayerEntity) user, TutorialNetworkingConstants.HIGHLIGHT_PACKET_ID, |
return TypedActionResult.success(user.getHandStack(hand)); | return TypedActionResult.success(user.getHandStack(hand)); | ||
} | } | ||
Line 105: | Line 105: | ||
To receive a packet from a server on the game client, your mod needs to specify how it will handle the incoming packet. | To receive a packet from a server on the game client, your mod needs to specify how it will handle the incoming packet. | ||
- | In your client entrypoint, you will register the receiver for your packet using '' | + | In your client entrypoint, you will register the receiver for your packet using '' |
The '' | The '' | ||
Line 112: | Line 112: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ClientPlayNetworking.registerGlobalReceiver(ModNetworkingConstants.HIGHLIGHT_PACKET_ID, | + | ClientPlayNetworking.registerGlobalReceiver(TutorialNetworkingConstants.HIGHLIGHT_PACKET_ID, |
... | ... | ||
}); | }); | ||
Line 122: | Line 122: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ClientPlayNetworking.registerGlobalReceiver(ModNetworkingConstants.HIGHLIGHT_PACKET_ID, | + | ClientPlayNetworking.registerGlobalReceiver(TutorialNetworkingConstants.HIGHLIGHT_PACKET_ID, |
client.execute(() -> { | client.execute(() -> { | ||
// Everything in this lambda is run on the render thread | // Everything in this lambda is run on the render thread | ||
Line 152: | Line 152: | ||
In the end, the client' | In the end, the client' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | ClientPlayNetworking.registerGlobalReceiver(ModNetworkingConstants.HIGHLIGHT_PACKET_ID, | + | ClientPlayNetworking.registerGlobalReceiver(TutorialNetworkingConstants.HIGHLIGHT_PACKET_ID, |
// Read packet data on the event loop | // Read packet data on the event loop | ||
BlockPos target = buf.readBlockPos(); | BlockPos target = buf.readBlockPos(); | ||
Line 183: | Line 183: | ||
buf.writeBlockPos(target); | buf.writeBlockPos(target); | ||
- | ServerPlayNetworking.send((ServerPlayerEntity) user, ModNetworkingConstants.HIGHLIGHT_PACKET_ID, | + | ServerPlayNetworking.send((ServerPlayerEntity) user, TutorialNetworkingConstants.HIGHLIGHT_PACKET_ID, |
return TypedActionResult.success(user.getHandStack(hand)); | return TypedActionResult.success(user.getHandStack(hand)); | ||
} | } | ||
Line 204: | Line 204: | ||
// Iterate over all players tracking a position in the world and send the packet to each player | // Iterate over all players tracking a position in the world and send the packet to each player | ||
for (ServerPlayerEntity player : PlayerLookup.tracking((ServerWorld) world, target)) { | for (ServerPlayerEntity player : PlayerLookup.tracking((ServerWorld) world, target)) { | ||
- | ServerPlayNetworking.send(player, | + | ServerPlayNetworking.send(player, |
} | } | ||
tutorial/networking.txt · Last modified: 2024/05/04 19:51 by bluemeanial