User Tools

Site Tools


tutorial:networking

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:networking [2019/12/26 22:11] – Added Fudge's networking modmuss50tutorial:networking [2020/10/20 03:37] – [Client To Server (C2S) Packets] Added link to keybinds tutorial nshak
Line 41: Line 41:
 ===== Server To Client (S2C) Packets ===== ===== Server To Client (S2C) Packets =====
  
-Server To Client, or S2C packets for short, allow the server to tell the clients to execute predefined code with some data. The clients will first need to know what to execute, so we will tell them just that during [**client** mod initialization]($$$ LINK TO CLIENT INIT DOC+Server To Client, or S2C packets for short, allow the server to tell the clients to execute predefined code with some data. The clients will first need to know what to execute, so we will tell them just that during  [[https://github.com/natanfudge/fabric-docs/blob/master/newdocs/Modding-Tutorials/Networking/the-client-mod-initializer.md|client mod initialization]]
  
 (Note that the identifier we will put in the class of the common initializer so it can be accessed from both sides:) (Note that the identifier we will put in the class of the common initializer so it can be accessed from both sides:)
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/05/04 19:51 by bluemeanial