Jump to content

Recommended Posts

Posted (edited)

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
  • Kiuseii changed the title to [1.19.3] Capabilities - Unknown custom packet but working
Posted

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

 

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); It says that '.get()' is deprecated since version 1.21.1 and has been marked for removal. How should I replace this line or section of code so it works? Or is there a way to fix it? Full Block of Code: IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();    // This is the line that's messed up... I don't know why modEventBus.addListener(this::commonSetup); MinecraftForge.EVENT_BUS.register(this);
    • Sorry to have bothered everyone.  I think I've figured it out: NbtUtils.snbtToStructure() will allow me to get the compound tag from a string I can load, and ItemStack.setTag() will allow me to write it to an item. Again, sorry to bother everyone -- it took a long time to work it out, it seems finding answers on the internet by googling isn't a viable way to get info so it took a lot of guessing, experimenting, and trial and error until I hit upon the path to a solution.
    • Hello, My modded forge server was working with no issues up until last night. The current issue is that the server crashes as soon as another player joins.   Steps I have already tried: Deleted these files: banned-ips.json, banned-players.json, ops.json, usercache.json, whitelist.json. Deleted all player files Deleted the chunk that player was in   Mods: Pixelmon 1.20.2, 9.2.10 Crash log: https://pastebin.com/qauuZLRE Latest Log: https://pastebin.com/TxCGS4sc Other issue I get when starting up the server: [LanServerPinger #1/WARN] [net.minecraft.client.server.LanServerPinger/]: LanServerPinger: Network is unreachable
    • I tried to reinstall the server multiple times but nothing worked and I keep getting the same error... I do have the correct java 21 installed or whatever it was. I couldn't find whats causing this problem as I tried a lot to reinstall the files again and again.
    • OK, what I need is to be able to take a JSON string, from a config file or data pack, and convert into NBT that can be applied to any arbitrary item (technically, item stack). This could easily be done in 1.12.2 using JsonToNBT.getTagFromJson(String data) like so: NBTFromJsonWrapper(String label, String data) { super(label, label); try { wrapped = JsonToNBT.getTagFromJson(data); } catch (NBTException e) { System.err.println("Exception reading json-nbt string: " + e.getMessage()); wrapped = new NBTTagCompound(); } } However, I can't seem to find a way to do this in newer version, specifically 1.19.4 (though once I'm done updating to that version I plan to be updating the latest 1.20 and 1.21 version). Alternately, of these NBT strings that resemble JSON but are not quite would be just as good, perhaps better: {ench:[{lvl:3s,id:35s},{lvl:5s,id:32s}],Unbreakable:1b,display:{Lore:["Believe it or not, this comes from ","an ancient Vanilla World. "],Name:"Fortuna Major"}} This was previously used for several purposes, one was simply to create purely vanilla potions.  The other was to create special items, primarily as trophies albeit practically useful trophies, often in the form of Easter Eggs. (I also had a homebrew system along side it, but I don't think I'll be updating it.) Any help would be appreciated.  Surely there is still a way to do this, and codecs do not seem to be the answer.  
  • Topics

×
×
  • Create New...

Important Information

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