Jump to content

[SOLVED][1.19.2] How to use FriendlyByteBuf Reader and Writer


Ezio214

Recommended Posts

I have a custom packet (Server to Client) with following snippet:

public CustomS2CPacket(FriendlyByteBuf buf) {
	this.test = (HashMap) buf.readMap(null, null); // why does this want two FriendlyByteBuf.Reader and how to implement them?
}

public void toBytes(FriendlyByteBuf buf) {
	buf.writeMap(this.test, null, null); // why does this want two FriendlyByteBuf.Writer and how to implement them?
}

 comments and title says it all.

Edited by Ezio214
Link to comment
Share on other sites

https://forge.gemwire.uk/wiki/Main_Page

Specifically, the "handling information" section.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

So I need a buf.write or buf.read method, ok. 

 

But how do I read a String. I found readCharSequence method but that wont work for me, because you need to tell him the length of the string.

this.test = buf.readMap(READSTRING, buf.readInt());

So would be nice instead of giving me links to wikis which only help me 60% to actually give me that 1 line of code, if you know.

 

writeMap I dont understand at all. First parameter is the map itself and then two writers. One for the keys and the other one for the entries.

buf.writeMap(this.test, KEYWRITER, ENTRYWRITER);

I have no clue what to write there, since for example buf.writeInt() (entry) needs the int it writes. Looking at the writeMap code there is forEach-loop which writes all the keys and entries. So I dont need to implement a loop only a one time method call.

 

SO all I'm asking is somebody to tell me, if you know, what I have to write at READSTRING, KEYWRITER and ENTRYWRITER.

Link to comment
Share on other sites

Quote

So would be nice instead of giving me links to wikis which only help me 60% to actually give me that 1 line of code, if you know.

This is not a teaching forum. Nor do we write your mod for you.

If we answered open ended questions based on random snippets of garbage code like your original question you would just keep coming back for more,

proxying the creation of your mod to us.

Instead, you need to think about what you are trying to do and research around the topic,

e.g. look at where the methods in question are used in vanilla or other mods doing the same thing.

 

When you have more specific questions that are real road blocks (not I spent 5 minutes trying to do this) you can ask here.

 

Since your latest question is based on specifics (but not sadly not much research), I will answer them.

Quote

But how do I read a String. I found readCharSequence method but that wont work for me, because you need to tell him the length of the string.

There are FriendlyByteBuffer.read/writeUTF() methods for strings. UTF is the java network format of Strings.

NOTE: It has a maximum size of 32K unicode characters. If you want more you need to split the string into multiple strings.

 

Quote

writeMap I dont understand at all. First parameter is the map itself and then two writers. One for the keys and the other one for the entries.

An example can be found in TagNetworkSerialization.NetworkPayload where is serializes a Map<ResourceLocation, IntList> using read/write functions for the respective keys/values.

There will be other examples if you search.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

If you gave me that example in the first place, everything would have been faster and clearer. Sry that I ask so much questions around Capabilites...

That system isn't that easy to understand and btw a "Modder Support" forum for me is like a place where I can definitely ask these things if I dont understand them.

Link to comment
Share on other sites

  • Ezio214 changed the title to [SOLVED][1.19.2] How to use FriendlyByteBuf Reader and Writer

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.