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 [2020/01/01 13:03] – fudge | tutorial:networking [2020/10/20 03:37] – [Client To Server (C2S) Packets] Added link to keybinds tutorial nshak | ||
---|---|---|---|
Line 163: | Line 163: | ||
Client to server packets follow the same principles. Some things can only be done from the server, such as changing the world in a way that affects other players, but you want them to be triggered by a client-only action, such as holding a keybinding. One key difference is that **you must validate what you receive in the '' | Client to server packets follow the same principles. Some things can only be done from the server, such as changing the world in a way that affects other players, but you want them to be triggered by a client-only action, such as holding a keybinding. One key difference is that **you must validate what you receive in the '' | ||
- | In this example we will replace a block with diamond when it is right clicked when a keybinding is held, using a C2S packet. If you want to know how to use hotkeys specifically, | + | In this example we will replace a block with diamond when it is right clicked when a keybinding is held, using a C2S packet. If you want to know how to use hotkeys specifically, |
As before we'll define an identifier for our packet: | As before we'll define an identifier for our packet: | ||
Line 210: | Line 210: | ||
// ALWAYS validate that the information received is valid in a C2S packet! | // ALWAYS validate that the information received is valid in a C2S packet! | ||
- | if(packetContext.getPlayer().world.isHeightValidAndBlockLoaded(pos)){ | + | if(packetContext.getPlayer().world.canSetBlock(pos)){ |
// Turn to diamond | // Turn to diamond | ||
packetContext.getPlayer().world.setBlockState(pos, | packetContext.getPlayer().world.setBlockState(pos, |
tutorial/networking.txt · Last modified: 2024/04/24 18:53 by skycatminepokie