Jump to content

Recommended Posts

Posted

It would be much less of a pain to send packets if I knew how to put NBT in them, it is possible, because when I spawn an entity, my NBT read code activates:

[13:26:48] [Server thread/INFO]: Saving and pausing game...
[13:26:48] [Server thread/INFO]: Saving chunks for level 'New World'/overworld
[13:26:48] [Server thread/INFO]: Saving chunks for level 'New World'/the_nether
[13:26:48] [Server thread/INFO]: Saving chunks for level 'New World'/the_end
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:77]: deser
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:83]: body_chestnut
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_whitefield
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_whitedots
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_white
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_blackfield
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_greyfield
[13:26:50] [Server thread/INFO]: [mods.giantnuker.horse.Markings:deserializeNBT:88]: mark:marks_white

This first prints the body image, body_chestnut, then all the additional markings the horse has, marks_whitedots, marks_greyfield.

Help would be nice :)

Posted

You can. ByteBufUtils.writeTag(buffer, nbt);

You can also send more than one value in a packet...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

You can. ByteBufUtils.writeTag(buffer, nbt);

You can also send more than one value in a packet...

Thank You!!!! :D

Never again will I have so much trouble sending strings :)

Posted
On 10/20/2017 at 0:42 AM, diesieben07 said:

Because there is no point in doing:


compound = new NBTTagCompound();
compound.setInt("foo", 123);
compound.setString("bar", "Hello World");
byteBuf.writeCompound(compound);

when you can just do:


byteBuf.writeInt(123);
byteBuf.writeString("Hello World");

 

 

The second version is more compact code-wise, it takes less bandwidth and it is more performant.

there is no writeString method in ByteBuf.

Posted

Knowing two things:

1) How to use my IDE

2) That strings are characters and characters are bytes

I worked this out on my own:

 

buf.writeBytes(("this is a string").getBytes());

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
54 minutes ago, Draco18s said:

Knowing two things:

1) How to use my IDE

2) That strings are characters and characters are bytes

I worked this out on my own:

 

buf.writeBytes(("this is a string").getBytes());

You should use ByteBufUtils.writeString and ByteBufUtils.readString instead.

Posted
1 minute ago, Silly511 said:

You should use ByteBufUtils.writeString and ByteBufUtils.readString instead.

The ByteBufUtils are awesome, and definitely a better choice.

But in terms of "here's what's in front of me, how can I solve this problem?" I could do it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

The ByteBufUtils are awesome, and definitely a better choice.

But in terms of "here's what's in front of me, how can I solve this problem?" I could do it.

I was about to edit my post when you replied, I should have been more specific. You can't use the code you posted because you can't read the string afterwards. You need to know how long the string is so you know how many bytes to read. ByteBufUtils.writeString will write the length so that ByteBufUtils.readString knows how many bytes to read.

Posted
On 10/17/2017 at 11:21 PM, diesieben07 said:

In my opinion, if you are sending NBT in a packet, 90% of the time you are doing something wrong.

I do it when I'm also planning to save / load the information. I know I can also do that in a raw file sort of way, but kinda nice to have one format that contains mixed data types that has helper classes for both packet and file serializers.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
8 minutes ago, Silly511 said:

because you can't read the string afterwards. You need to know how long the string is so you know how many bytes to read.

Oh gosh, leaving an exercise to the reader about writing in the length of the string first! The horror!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.