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 revision
Previous revision
Next revisionBoth sides next revision
tutorial:networking [2020/01/01 13:03] fudgetutorial: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 ''%%PacketByteBuf%%''**. 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 ''%%PacketByteBuf%%''**.
  
-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, refer to the [hotkeys tutorial]($$$ LINK TO KEYBINDINGS TUTORIAL+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, refer to the [[tutorial:keybinds|hotkeys tutorial]]
  
 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, Blocks.DIAMOND_BLOCK.getDefaultState());                     packetContext.getPlayer().world.setBlockState(pos, Blocks.DIAMOND_BLOCK.getDefaultState());
tutorial/networking.txt · Last modified: 2024/04/24 18:53 by skycatminepokie