Changes

480 bytes added ,  00:30, 29 March 2022
There's your code example shrimp!
Line 36: Line 36:     
The last three parameters can be method references to either static or instance methods in Java. Remember that an instance method <code><nowiki>MSG.encode(FriendlyByteBuf)</nowiki></code> still satisfies <code><nowiki>BiConsumer<MSG, FriendlyByteBuf></nowiki></code>, the <code><nowiki>MSG</nowiki></code> simply becomes the implicit first argument.
 
The last three parameters can be method references to either static or instance methods in Java. Remember that an instance method <code><nowiki>MSG.encode(FriendlyByteBuf)</nowiki></code> still satisfies <code><nowiki>BiConsumer<MSG, FriendlyByteBuf></nowiki></code>, the <code><nowiki>MSG</nowiki></code> simply becomes the implicit first argument.
 +
 +
<syntaxhighlight lang="java">
 +
// A class MessagePacket
 +
public void encoder(FriendlyByteBuf buffer) {
 +
  // Write to buffer
 +
}
 +
 +
public static MessagePacket decoder(FriendlyByteBuf buffer) {
 +
  // Create packet from buffer data
 +
}
 +
 +
public void messageConsumer(Supplier<NetworkEvent.Context>> ctx) {
 +
  // Handle message
 +
}
 +
 +
// For some SimpleChannel channel
 +
channel.registerMessage(id, MessagePacket::encoder, MessagePacket::decoder, MessagePacket::messageConsumer);
 +
</syntaxhighlight>
    
== Handling Packets ==
 
== Handling Packets ==