Skip to content

Network Packet Module >=1.21.1

Availability

NetworkUtil (batch-sending utilities) was not synchronized in versions 1.21.2-1.21.11; it is only available in 1.21.1 and 26.1. All other APIs are consistent across all versions.

The package dev.anvilcraft.lib.v2.network provides a high-level abstraction over the NeoForge networking system to simplify packet definition, direction management, and automatic registration.

Documentation Index

DocumentContent
Packet InterfacesIPacket, IClientboundPacket, IServerboundPacket, bidirectional packets
Registration System@Network annotation, NetworkRegistrar, PacketProtocol
Sending UtilitiesNetworkUtil batch-sending methods

Core Workflow

  1. Define a packet class, implement the corresponding interface (e.g., IClientboundPacket), and declare static final Type<?> and StreamCodec
  2. Add the @Network annotation to package-info.java, specifying the protocol phase
  3. Call NetworkRegistrar.register(registrar, modId) inside RegisterPayloadHandlersEvent

Notes

  • Packet classes must have a no-arg constructor (typically using records)
  • NetworkRegistrar looks up Type and StreamCodec static fields via reflection
  • If registration throws an exception, check whether the packet class is missing static fields or fails to implement the expected interface

Released under the CC-BY-NC-SA 4.0 License.