Jump to content

Can't find proper document on the network reworking on forge 48.1.0'


Recommended Posts

Hello,
for educational purpose I am trying to port a mod from 1.20.1 to 1.20.2+ but I can't understand how the new networking system works.
I manage to get through it for the most part, but I'm stuck on how to register packets.
The previous method was:
INSTANCE.registerMessage(id++, CPExecuteSkill.class, CPExecuteSkill::toBytes, CPExecuteSkill::fromBytes, CPExecuteSkill::handle);
with instance being of type SimpleChannel. 
(The forge document is not up to date for this part unfortunatly)

Any help or clear documentation would be welcome.

Link to comment
Share on other sites

thast right 
kapenjoe says something about not going up from 1.20.2 for some package issue 

i have the mine working messing around until the code start working still seems like you have some more complex than the mine 

 

//in mi main class 

	//########## ########## ########## ########## ########## ########## ########## ##########
private void commonSetup(final FMLCommonSetupEvent event) {
ModMessage.register();
}
	

 

ModMessage.class

Spoiler

				
			package mercmod.networking;				
			import mercmod.mercmod;
		import net.minecraft.resources.ResourceLocation;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraftforge.network.ChannelBuilder;
		import net.minecraftforge.network.NetworkDirection;
		import net.minecraftforge.network.PacketDistributor;
		import net.minecraftforge.network.SimpleChannel;				
			public class ModMessage {				
			    private static int packetId = 0;				
			    private static int id() {
		        return packetId++;
		    }				
			    public static final SimpleChannel INSTANCE = ChannelBuilder.named(
		                    new ResourceLocation(mercmod.MOD_ID, "main"))
		            .clientAcceptedVersions((status, versions) -> true)
		            .serverAcceptedVersions((status, versions) -> true)
		            .networkProtocolVersion(1)
		            .simpleChannel();				
			    public static void register() {				
			        INSTANCE.messageBuilder(toggle_crawl.class, id(), NetworkDirection.PLAY_TO_SERVER)
		                .decoder(toggle_crawl::new)
		                .encoder(toggle_crawl::toBytes)
		                .consumerMainThread(toggle_crawl::handle)
		                .add();				
			        INSTANCE.messageBuilder(set_crawl_locally.class, id(), NetworkDirection.PLAY_TO_CLIENT)
		                .decoder(set_crawl_locally::new)
		                .encoder(set_crawl_locally::toBytes)
		                .consumerMainThread(set_crawl_locally::handle)
		                .add();				
			        INSTANCE.messageBuilder(send_display_mensage_locally.class, id(), NetworkDirection.PLAY_TO_CLIENT)
		                .decoder(send_display_mensage_locally::new)
		                .encoder(send_display_mensage_locally::toBytes)
		                .consumerMainThread(send_display_mensage_locally::handle)
		                .add();				
			    }				
			    public static void sendToServer(Object message) {
		        INSTANCE.send(message, PacketDistributor.SERVER.noArg());
		    }				
			    public static void sendToPlayer(Object message, ServerPlayer pe) {//
		        INSTANCE.send(message, PacketDistributor.PLAYER.with(pe));
		    }				
			    public static void sendToAllClients(Object message) {				
			        INSTANCE.send(message, PacketDistributor.ALL.noArg());
		    }				
			}
		 				
			

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.