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,

 

I am trying to send a nbt tag from sever to client using packets.

But I get a long error at my fromBytes(ByteBuf) method.

There is really much data in the nbt tag.

Does anybody know why I get this error:

 

Reveal hidden contents

 

 

Here is the message class:

public class NBTMessage implements IMessage{

public NBTTagCompound nbt;

@Override
public void fromBytes(ByteBuf buf) {
	nbt = ByteBufUtils.readTag(buf);
}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeTag(buf, nbt);
}

public NBTMessage() {}
public NBTMessage(NBTTagCompound compound){
	nbt = compound;
}
public static class Handler implements IMessageHandler<NBTMessage, IMessage> {

	@Override
	public IMessage onMessage(NBTMessage message, MessageContext ctx) {
		System.out.println("nbt = " + message.nbt);
                        WorldData.nbt = message.nbt;
		return null;
	}

}
}

 

This is the method I use that sends and receives the packet:

public static void updateClient(World world){
	if(world != null){
		WorldData data = get(world);
		if(!world.isRemote){
			KnokkoRPG.network.sendToAll(new NBTMessage(data.players));
		}
		if(world.isRemote){
			data.players = nbt;
		}
	}
}

Hi

 

How big is your nbt?  perhaps it is too big.

 

Try putting

 

System.out.println("Buffer contents: " + buf.readableBytes());

 

in your fromBytes (before readTag) and your toBytes (after writeTag)

 

that might give a clue

 

-TGG

  • Author

Ok, I dit what you said.

 

Here is the new message in the console.

Buffer contents: 812026

Buffer contents: 812025

The crash reappeared of course.

 

But I don't know the limit and I know almost nothing about bytes, so is this too much?

 

Here is the toString method of the nbt tag I want to send:

 

Reveal hidden contents

 

It wouldn't surprise me if this is just too much data.

  On 11/6/2014 at 2:31 PM, knokko said:

Ok, I dit what you said.

 

Here is the new message in the console.

Buffer contents: 812026

 

Too much data.  Maximum packet size, IIRC, is ~32,000 (32,767).  That or ~64,000 (65,535), I forget which but either way, 812,000 is an order of magnitude larger.

 

Somewhere....curses, can't find it, but diesieben07 has a package somewhere that will automatically break large packets up into smaller ones and reconstruct them.

 

Edit:

Found the project I used it for, which is 1.6.4, but it might help.

https://dl.dropboxusercontent.com/u/7950499/LinkRenders.zip

Essentially what that mod does is plugin to Mystcraft and store bitmap data in an NBT that it saves and reads from the server hard drive, transmitting the data with packets (took 4 when I was doing it manually).  I verified that the MultipartPacket classes are in the archive, so that appears to be close to the last version I was working on (I stopped, as I got it to "usable" and someone else came along and did one better having been inspired what I had accomplished).

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.

  On 11/6/2014 at 2:31 PM, knokko said:

Ok, I dit what you said.

 

Here is the new message in the console.

Buffer contents: 812026

Buffer contents: 812025

The crash reappeared of course.

 

But I don't know the limit and I know almost nothing about bytes, so is this too much?

I think the apparent mismatch in buffer size is ok, the extra one byte in the sending packet is the packet discriminator byte.  And all of your sent data makes it to the recipient.

 

The cause is a bug in vanilla minecraft.  It assumes the compressed data length will fit into a short (32767).  If it doesn't, it overflows so the decompressor gets a wrong length.

PacketBuffer::
    /**
     * Writes a compressed NBTTagCompound to this buffer
     */
    public void writeNBTTagCompoundToBuffer(NBTTagCompound p_150786_1_) throws IOException
    {
        if (p_150786_1_ == null)
        {
            this.writeShort(-1);
        }
        else
        {
            byte[] abyte = CompressedStreamTools.compress(p_150786_1_);
            this.writeShort((short)abyte.length);                                                     /// aiiiee noob coding mistake
            this.writeBytes(abyte);
        }
    }

 

The good news is, that large packet made it across no problems.  I reckon all you need to do is copy out the vanilla code for compressing the data and change the short to an int.

 

-TGG

 

  • Author

It was an error of me that there was so much data anyway, I am rewriting my worldata, now it is more than 50 times shorter.

Now the buffer contents is 150, and the packet arrives without problems.

I think I am done.

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.