Skip to content

Networking Guide #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 7, 2025
Merged

Networking Guide #249

merged 18 commits into from
Mar 7, 2025

Conversation

dicedpixels
Copy link
Contributor

@dicedpixels dicedpixels commented Dec 31, 2024

Ports Networking.

Differences:

  • Actual working item, Lightning Tater.
  • Along with S2C, a C2S example is also included.

Copy link

netlify bot commented Dec 31, 2024

Deploy Preview for nimble-elf-d9d491 ready!

Name Link
🔨 Latest commit 7d13374
🔍 Latest deploy log https://app.netlify.com/sites/nimble-elf-d9d491/deploys/67cb213557e42c000802994b
😎 Deploy Preview https://deploy-preview-249--nimble-elf-d9d491.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@IMB11 IMB11 added new-content A new page or set of pages stage:verification This should be verified labels Dec 31, 2024
@IMB11
Copy link
Member

IMB11 commented Jan 15, 2025

Hi! The documentation has been updated to version 1.21.4. Please rebase your PR and update your code to align with the latest version.

Alternatively, you can create a new branch based on the latest commit from the FabricMC:main branch, copy over your changes from the old dicedpixels:networking branch, update it, and open a new PR - this approach is often simpler than dealing with complex git commands if you're not the best git wrangler.

Once you've completed the updates and are confident everything is ready, feel free to unmark this as a draft. Thanks again for your contribution!

@its-miroma its-miroma added stage:expansion This should be expanded and removed stage:verification This should be verified labels Jan 18, 2025
@its-miroma its-miroma mentioned this pull request Jan 29, 2025
30 tasks
@its-miroma
Copy link
Member

Hello @dicedpixels, are you still working on this?

- remove dedicated data generator
- add lightning tater item model generator to the shared pack
- fix offset line numbers
- fix broken link in damage types doc
- add more info about `PlayerLookup` and adjust the code
- limt the `UseItemCallback` to the logical client
- attempted to improve the c2s section to align with review comments
@dicedpixels
Copy link
Contributor Author

Hello @dicedpixels, are you still working on this?

I guess so 😅. Haven't had time to sit and look back at it. I believe I've addressed all the comments, PR should be up-to-date. I will undraft it so more people can review.

@dicedpixels dicedpixels marked this pull request as ready for review February 26, 2025 15:29
@dicedpixels dicedpixels requested a review from a team as a code owner February 26, 2025 15:29
@its-miroma its-miroma added stage:verification This should be verified and removed stage:expansion This should be expanded labels Feb 26, 2025
@its-miroma its-miroma requested a review from Octol1ttle March 5, 2025 10:11
IMB11
IMB11 previously requested changes Mar 5, 2025
Copy link
Member

@IMB11 IMB11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good quality page! Well done. Just a very minor nitpick and then LGTM I think!

its-miroma
its-miroma previously approved these changes Mar 7, 2025
@its-miroma
Copy link
Member

still not convinced with the diagram being an image, but there's not much to do about it

@its-miroma its-miroma added stage:ready This is ready to be merged and removed stage:verification This should be verified labels Mar 7, 2025
@its-miroma its-miroma dismissed IMB11’s stale review March 7, 2025 16:42

not applicable (the example is intentionally wrong and as such can't be in the mod)

Comment on lines +54 to +79
Upon testing, you will see a lightning bolt being summoned and nothing crashes. Now you want to show the mod to your
friend, you boot up a dedicated server and invite your friend on with the mod installed.

You use the item and the server crashes. You will probably notice in the crash log an error similar to this:

```log
[Server thread/FATAL]: Error executing task on Server
java.lang.RuntimeException: Cannot load class net.minecraft.client.MinecraftClient in environment type SERVER
```

### Why Does the Server Crash? {#why-does-the-server-crash}

The code calls logic only present on the client distribution of the Minecraft. The reason for Mojang distributing the
game in this way is to cut down on the size of the Minecraft Server JAR file. There isn't really a reason to include an
entire rendering engine when your own machine will render the world.

In a development environment, client-only classes are indicated by the `@Environment(EnvType.CLIENT)` annotation.

### How Do We Fix the Crash? {#how-do-we-fix-the-crash}

To fix this issue, you need to understand how the game client and dedicated server communicate:

![Sides](/assets/develop/networking/sides.png)

The diagram above shows that the game client and dedicated server are separate systems, bridged together using
_packets_. Packets can contain data which we refer to as the _payload_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine I guess, it just doenst have anything to do with networking. Packets are still sent between the logicial client and server even in single player, or when on a LAN world. A better example would be to cause desync by setting something only the logicial client. Maybe try adding a block to the hotbar from a keybind or something.

@its-miroma its-miroma merged commit daff204 into FabricMC:main Mar 7, 2025
7 checks passed
@ArisuwuMei ArisuwuMei mentioned this pull request May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-content A new page or set of pages stage:ready This is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants