Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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());
		    }				
			}
		 				
			

 

 

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.