Jump to content

[1.19.3] Capabilities - Unknown custom packet but working


Kiuseii

Recommended Posts

Hello,

 

I'm getting Unknown custom packet identifier: argonauts:simple_channel but when i send the packet it works. After some search, the problem could be the symmetry of encoding and decoding but even after writing a simple buf.readInt() and buf.writeInt() i also get the message.

 

Also, i'm sending an nbt with my packet. I've seen that it exist buf.writerIndex() but don't know how to correctly use it. (Show i just use index + 1 each time i had something, or should i use an other number ?) Could i add multiple data in one buffer ?

 

I'm send that packet each tick when i refill the mana capability of the player.

 

Here is the source of my packet : https://github.com/Ddasb/argonauts/blob/master/src/main/java/com/kiuseii/argonauts/network/packets/AttributesDataSyncS2CPacket.java

Source of my capability : https://github.com/Ddasb/argonauts/blob/master/src/main/java/com/kiuseii/argonauts/capabilities/attributes/AttributesCapability.java

My Packet handler : https://github.com/Ddasb/argonauts/blob/master/src/main/java/com/kiuseii/argonauts/network/PacketHandler.java

Where i refill the mana  https://github.com/Ddasb/argonauts/blob/master/src/main/java/com/kiuseii/argonauts/events/ModEvents.java

 

Thanks for the help provided

Edited by Kiuseii
Link to comment
Share on other sites

  • Kiuseii changed the title to [1.19.3] Capabilities - Unknown custom packet but working

using your code i fix mi issue 
in your code i dont see the problem but the way is structured is way different from the mine 

 

Main.class

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

 

ModMessage.class

Spoiler

				
			package merctool.networking;				
			import net.minecraft.resources.ResourceLocation;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraftforge.network.NetworkDirection;
		import net.minecraftforge.network.NetworkRegistry;
		import net.minecraftforge.network.PacketDistributor;
		import net.minecraftforge.network.simple.SimpleChannel;
		import merctool.merctool;				
			public class ModMessage{				
			     private static SimpleChannel INSTANCE;
		     private static int packetId = 0;
		     
		     private static int id() {
		         return packetId ++;
		     }
		     
		     public static void register() {
		         
		         SimpleChannel net = NetworkRegistry.ChannelBuilder
		                 .named(new ResourceLocation( merctool.MOD_ID, "messages"))
		         .networkProtocolVersion(() -> "1.0")
		         .clientAcceptedVersions(s -> true)
		         .serverAcceptedVersions(s -> true)
		         .simpleChannel();
		         
		         INSTANCE = net;
		         
		         //
		            net.messageBuilder(onmousedown_middle.class, id(), NetworkDirection.PLAY_TO_SERVER)
		         .decoder(onmousedown_middle::new)
		         .encoder(onmousedown_middle::toBytes)
		         .consumerMainThread(onmousedown_middle::handle)
		         .add();				
			         //
		            net.messageBuilder(onmouseup_middle.class, id(), NetworkDirection.PLAY_TO_SERVER)
		         .decoder(onmouseup_middle::new)
		         .encoder(onmouseup_middle::toBytes)
		         .consumerMainThread(onmouseup_middle::handle)
		         .add();				
			         //
		            net.messageBuilder(onmousedown_left.class, id(), NetworkDirection.PLAY_TO_SERVER)
		         .decoder(onmousedown_left::new)
		         .encoder(onmousedown_left::toBytes)
		         .consumerMainThread(onmousedown_left::handle)
		         .add();				
			         //
		            net.messageBuilder(onmouseup_left.class, id(), NetworkDirection.PLAY_TO_SERVER)
		         .decoder(onmouseup_left::new)
		         .encoder(onmouseup_left::toBytes)
		         .consumerMainThread(onmouseup_left::handle)
		         .add();
		                  
		         
		     }
		     
		     public static <MSG> void sendToServer(MSG message) {
		         INSTANCE.sendToServer(message);
		     }
		     
		     public static <MSG> void sendToPlayer(MSG message, ServerPlayer pe) {
		         INSTANCE.send( PacketDistributor.PLAYER.with( () -> pe),  message) ;
		     }     
		     
		     
		     
		     
		     
		     
		 }				
			

 

onmouseup_middle.class

Spoiler

				
			package merctool.networking;				
			import net.minecraft.nbt.CompoundTag;
		import net.minecraft.network.FriendlyByteBuf;
		import net.minecraft.server.level.ServerLevel;
		import net.minecraft.server.level.ServerPlayer;
		import net.minecraft.world.entity.EntityType;
		import net.minecraft.world.entity.MobSpawnType;
		import net.minecraftforge.network.NetworkEvent;				
			import java.util.function.Supplier;				
			public class onmouseup_middle {
		    
		    private int val0 = 0;
		    private int val1 = 0;
		    
		    
		    public onmouseup_middle(int val0, int val1) {
		        this.val0 = val0;
		        this.val1 = val1;
		    }				
			    public onmouseup_middle(FriendlyByteBuf buf) {
		         CompoundTag nbt = buf.readNbt();
		        
		        this.val0 = nbt.getInt("val0");
		        this.val1 = nbt.getInt("val1");				
			    }				
			    public void toBytes(FriendlyByteBuf buf) {
		        CompoundTag nbt = new CompoundTag();
		        
		        nbt.putInt("val0", val0);
		        nbt.putInt("val1", val1);
		        
		        buf.writeNbt(nbt);
		    }				
			    public boolean handle(Supplier<NetworkEvent.Context> supplier) {
		        NetworkEvent.Context context = supplier.get();
		        context.enqueueWork(() -> {
		            // HERE WE ARE ON THE SERVER!
		            ServerPlayer player = context.getSender();
		            ServerLevel level = player.getLevel();
		            
		            System.out.println("Package recived");
		            System.out.println("val0=" + val0);
		            System.out.println("val1=" + val1);
		                        
		            //EntityType.COW.spawn(level, null, null, player.blockPosition(),
		                   //MobSpawnType.COMMAND, true, false);
		        });
		        return true;
		    }				
			}				
			

 

i send the event whit 

ModMessage.sendToServer(new onmouseup_middle(3,7));

 

mi code actually does nothing just send two numbers on middle click 

 

 

	[07:50:01] [Render thread/INFO] [minecraft/ChatComponent]: [System] [CHAT] Drinking WATA
	Package recived
	val0=3
	val1=7
	[07:50:01] [Render thread/INFO] [minecraft/ChatComponent]: [System] [CHAT] Drinking WATA
	Package recived
	val0=3
	val1=7
	[07:50:01] [Render thread/INFO] [minecraft/ChatComponent]: [System] [CHAT] Drinking WATA
	Package recived
	val0=3
	val1=7
	[07:50:01] [Render thread/INFO] [minecraft/ChatComponent]: [System] [CHAT] Drinking WATA
	Package recived
	val0=3
	val1=7
	[07:50:06] [Server thread/INFO] [minecraft/IntegratedServer]: Saving and pausing game...
	

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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