-
Notifications
You must be signed in to change notification settings - Fork 1
Modules Network
The first module added to Compound was networking, it was created to address certain shortcomings of other networking libraries for MinecraftForge.
Networking is based around two core concepts: Messages and Marshallers.
Messages define a set of data to send to the server/client, and how that data should be handled when received.
Marshallers define how a type of data is to be sent over the wire. Compound already has implementations for all primitives, Strings, NBT Data and Vec3i. If there's a custom data structure in your mod that needs to be sent over the wire then you can define a custom marshaller using the @RegisteredMarshaller annotation.
To setup Networking in your project first you need to create a channel that you can register your packets in, this should be done during the FMLCommonSetupEvent. You can register your channel with one line.
CompoundNetwork.createNetwork(ModLoadingContext.get().getActiveContainer(), "channel_name");Now that you have a network channel registered you can begin adding packets by extending the Message class and annotating them with @RegisteredMarshaller to register them to your channel.
Once you've created your message and annotated it to register you can send messages by instantiating the message and calling any of the built-in methods to send it to the appropriate targets.
For an example of the Network module in use please see Molecule, the test mod for Compound.