Jump to content

Recommended Posts

Posted

I get this error with Forge 1.7.2-10.12.0.1047 (I got a similar one in 1.6.4 too, I thought it would be fixed with the new packet system, but it isn't):

http://pastebin.com/gus7Rcwq

 

I don't know what packet the error is related to, so I don't know what code I could post here... (not gonna post my whole project, 100.000+ lines)

 

Do you maybe know how an error like this is caused and how to fix it?

Posted

That's being caused by one of your custom TileEntity's description packets. When you send the packet, there is an identifier that goes in the packet signature; I always use '1' and it works fine:

return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);

 

If that's not your issue, then as Jwosty suggests we will need to see more of your code.

Posted

That's being caused by one of your custom TileEntity's description packets. When you send the packet, there is an identifier that goes in the packet signature; I always use '1' and it works fine:

return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);

 

If that's not your issue, then as Jwosty suggests we will need to see more of your code.

 

I used 1 and got some errors so squituri told me this:

 

Your description packet has type 4 (4th argument) this indicates a vanilla TileEntityMobSpawner is the target of that description packet. That is probably why it doesn't like the length.

1 - TileEntityModSpawner

2 - TileEntityCommandBlock

3 - TileEntityBeacon

4 - TileEntitySkull

5 - TileEntityFlowerPot

 

Of course, your TE would need to use a different ID byte.

 

I'm using 7 now.

 

NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 7, nbttagcompound);

 

 

 

Can you post your channel handler class (implements FMLIndexedMessageToMessageCodec) and your packet class?

I'm using

AssemblyPacketHandler packethandler = new AssemblyPacketHandler();
NetworkRegistry.INSTANCE.newEventDrivenChannel("Sorter").register(packethandler);
NetworkRegistry.INSTANCE.newEventDrivenChannel("Counter").register(packethandler);

AssemblyPacketHandler:

 

@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) {
World world = ((NetHandlerPlayServer) event.handler).playerEntity.worldObj;
if (event.packet.channel().equals("Sorter")) {
	handlerSorterPacket(event.packet, world);
} else if (event.packet.channel().equals("Counter")) {
	handlerCounterPacket(event.packet, world);
}
}

@SubscribeEvent
public void onClientPacket(ClientCustomPacketEvent event) {
}

 

 

Is this wrong?

Posted

NetworkRegistry.INSTANCE.newEventDrivenChannel("Counter").register(packethandler);

You need to save the result of #newEventDrivenChannel(String) or you'll never be able to send a packet on your channel.

Posted

You need to save the result of #newEventDrivenChannel(String) or you'll never be able to send a packet on your channel.

 

What do I need it for?

I was sending packets like this:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(bos);
try {
outputStream.writeInt(tile.xCoord);
outputStream.writeInt(tile.yCoord);
outputStream.writeInt(tile.zCoord);
outputStream.writeBoolean(active);
} catch (Exception ex) {
ex.printStackTrace();
}
C17PacketCustomPayload packet = new C17PacketCustomPayload("Sorter", bos.toByteArray());
mc.getNetHandler().addToSendQueue(packet);

Posted

You need to save the result of #newEventDrivenChannel(String) or you'll never be able to send a packet on your channel.

 

What do I need it for?

I was sending packets like this:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream outputStream = new DataOutputStream(bos);
try {
outputStream.writeInt(tile.xCoord);
outputStream.writeInt(tile.yCoord);
outputStream.writeInt(tile.zCoord);
outputStream.writeBoolean(active);
} catch (Exception ex) {
ex.printStackTrace();
}
C17PacketCustomPayload packet = new C17PacketCustomPayload("Sorter", bos.toByteArray());
mc.getNetHandler().addToSendQueue(packet);

 

Edit:

Is this tutorial up-to-date now? (http://www.minecraftforge.net/wiki/Tutorials/Packet_Handling)

Then I will just try that one seems I didn't know that I had to change the sending too...

 

Do you still have some kind of solution for 1.6.4? (Want to make my mod compatible with 1.6.4 because many are still using that version)

Posted

That's being caused by one of your custom TileEntity's description packets. When you send the packet, there is an identifier that goes in the packet signature; I always use '1' and it works fine:

return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound);

 

If that's not your issue, then as Jwosty suggests we will need to see more of your code.

 

I used 1 and got some errors so squituri told me this:

 

I'm using 7 now.

 

Is this wrong?

If using 1 didn't work then the id is not your issue, the issue is as GotoLink mentioned with your packet system - the packet-handling tutorial you mention is up to date for 1.6.4.

 

Actually, if you are coding for 1.6.4, the packet class is totally different: Packet132TileEntityData in 1.6.4, S35PacketUpdateTileEntity in 1.7.2., so that may have been one of your errors as well. Are you trying to code both versions at the same time??? Might be easier to focus on one version first, so we can provide more reliable answers.

Posted

If using 1 didn't work then the id is not your issue, the issue is as GotoLink mentioned with your packet system - the packet-handling tutorial you mention is up to date for 1.6.4.

 

Actually, if you are coding for 1.6.4, the packet class is totally different: Packet132TileEntityData in 1.6.4, S35PacketUpdateTileEntity in 1.7.2., so that may have been one of your errors as well. Are you trying to code both versions at the same time??? Might be easier to focus on one version first, so we can provide more reliable answers.

 

To clarify: I used 1.6.4 and the error came and I found no solultion so I tried with 1.7.2...

My packet system is now updated to Netty with this: http://www.minecraftforge.net/wiki/Tutorials/Packet_Handling

=> Working perfectly fine

 

 

Posted

But one TileEntityDescriptionPacket is still causing trouble: (not handled via my packethandler)

http://pastebin.com/CqAjbuxj

Is there some sort of maximum size? How can I avoid that?

 

Code:

 

public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 7, nbttagcompound);
}

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readFromNBT(packet.func_148857_g());
}

 

Posted

Post your read and write NBT methods from your TileEntity.

 

Here it is: :)

public void readFromNBT(NBTTagCompound nbttagcompound) {
if (nbttagcompound == null) {
	Assembly.logger.warn("AssemblyCounter should read from null NBT ?!");
	return;
}
super.readFromNBT(nbttagcompound);
NBTTagCompound nbt = nbttagcompound.getCompoundTag("counterdata");

int countersize = nbt.getInteger("countersize");

for (int i = 0; i < countersize; i++) {
	int id = nbt.getInteger("counter" + i + "_id");
	int damage = nbt.getInteger("counter" + i + "_damage");
	int count = nbt.getInteger("counter" + i + "_count");
	counter.put(new int[] { id, damage }, Integer.valueOf(count));
}
}

public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagCompound nbt = new NBTTagCompound();

nbt.setInteger("countersize", counter.size());

Iterator<Entry<int[], Integer>> it = counter.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
	Entry<int[], Integer> entry = (Entry<int[], Integer>) it.next();
	nbt.setInteger("counter" + i + "_id", ((int[]) entry.getKey())[0]);
	nbt.setInteger("counter" + i + "_damage", ((int[]) entry.getKey())[1]);
	nbt.setInteger("counter" + i + "_count", ((Integer) entry.getValue()).intValue());
	i++;
}
nbttagcompound.setTag("counterdata", nbt);
}

Posted

Hm. Don't see anything odd there... but looking back at your error log there does indeed seem to be a limit:

io.netty.handler.codec.DecoderException: java.io.IOException: The received encoded string buffer length is longer than maximum allowed (724188 > 256)

 

I'm not sure if that existed in 1.6.4 or not, but it looks like you are going to have to handle your TileEntity using a custom packet, and possibly even split the data up into several packets. I would just avoid the description packet altogether for this one, given the apparently tiny size it is allotted.

Posted

Hm. Don't see anything odd there... but looking back at your error log there does indeed seem to be a limit:

io.netty.handler.codec.DecoderException: java.io.IOException: The received encoded string buffer length is longer than maximum allowed (724188 > 256)

 

I'm not sure if that existed in 1.6.4 or not, but it looks like you are going to have to handle your TileEntity using a custom packet, and possibly even split the data up into several packets. I would just avoid the description packet altogether for this one, given the apparently tiny size it is allotted.

 

So should I split my data into 3000 packets?! It's not that much, just an array with 10-50 entries O.o

Posted

I'm not sure how your data got to be 724188 bits if you only have 50 entries of 3 integers, so it could very well be something else going on.

 

At any rate, a normal packet should not have this restriction, if it is indeed some special restriction enforced on TileEntity description packets.

 

Another option is to find a more compact way of storing your data, rather than three keys per entry, you can do it in one using NBTTagCompound.setIntArray(String, int[]):

while (it.hasNext()) {
Entry<int[], Integer> entry = (Entry<int[], Integer>) it.next();
nbt.setIntArray("counter" + i, new int[] {((int[]) entry.getKey())[0], ((int[]) entry.getKey())[1], ((Integer) entry.getValue()).intValue()});
i++;
}

I'm sure there's a better way to write it without all those casts, but you get the idea.

Posted

You should clear the "counter" map in #onDataPacket, before #readFromNBT.

counter.put(new int[] { id, damage }, Integer.valueOf(count));

Int arrays aren't good for keys in a map. They don't behave like you think they would.

 

Posted

This code might save a few bytes of space. But, I haven't tested it, so use as your own risk.

 

    @Override
    public void readFromNBT(final NBTTagCompound nbttagcompound) {
        if (nbttagcompound == null)
            //Assembly.logger.warn("AssemblyCounter should read from null NBT ?!");
            return;
        super.readFromNBT(nbttagcompound);
        NBTTagCompound cdTag = nbttagcompound.getCompoundTag("counterdata");
        int sizes = cdTag.getInteger("countersize");
        int[] ids = cdTag.getIntArray("id");
        int[] damages = cdTag.getIntArray("damage");
        int[] counts = cdTag.getIntArray("count");
        counter.clear();
        for (int i = 0; i < sizes; ++i)
            counter.put(new int[] {ids[i],  damages[i]}, counts[i]);
    }
    @Override
    public void writeToNBT(final NBTTagCompound nbttagcompound) {
        super.writeToNBT(nbttagcompound);
        final NBTTagCompound nbt = new NBTTagCompound();

        nbt.setInteger("countersize", counter.size());
        final int[][] splat = split(counter.keySet());
        nbt.setIntArray("id",  splat[0]);
        nbt.setIntArray("damage", splat[1]);
        nbt.setIntArray("count", ArrayUtils.toPrimitive(counter.values().toArray(new Integer[0])));

        nbttagcompound.setTag("counterdata", nbt);
    }
    int[][] split(final Set<int[]> in) {
        final int[] a0 = new int[in.size()];
        final int[] a1 = new int[in.size()];
        int o = 0;
        for (final int[] a: in) {
            a0[o] = a[0];
            a1[o++] = a[1];
        }
        return new int[][] { a0, a1};
    }

 

  • 2 weeks later...
Posted

This code might save a few bytes of space. But, I haven't tested it, so use as your own risk.

 

    @Override
    public void readFromNBT(final NBTTagCompound nbttagcompound) {
        if (nbttagcompound == null)
            //Assembly.logger.warn("AssemblyCounter should read from null NBT ?!");
            return;
        super.readFromNBT(nbttagcompound);
        NBTTagCompound cdTag = nbttagcompound.getCompoundTag("counterdata");
        int sizes = cdTag.getInteger("countersize");
        int[] ids = cdTag.getIntArray("id");
        int[] damages = cdTag.getIntArray("damage");
        int[] counts = cdTag.getIntArray("count");
        counter.clear();
        for (int i = 0; i < sizes; ++i)
            counter.put(new int[] {ids[i],  damages[i]}, counts[i]);
    }
    @Override
    public void writeToNBT(final NBTTagCompound nbttagcompound) {
        super.writeToNBT(nbttagcompound);
        final NBTTagCompound nbt = new NBTTagCompound();

        nbt.setInteger("countersize", counter.size());
        final int[][] splat = split(counter.keySet());
        nbt.setIntArray("id",  splat[0]);
        nbt.setIntArray("damage", splat[1]);
        nbt.setIntArray("count", ArrayUtils.toPrimitive(counter.values().toArray(new Integer[0])));

        nbttagcompound.setTag("counterdata", nbt);
    }
    int[][] split(final Set<int[]> in) {
        final int[] a0 = new int[in.size()];
        final int[] a1 = new int[in.size()];
        int o = 0;
        for (final int[] a: in) {
            a0[o] = a[0];
            a1[o++] = a[1];
        }
        return new int[][] { a0, a1};
    }

 

 

I already thought of that, but that would kill backwards compatiblity. I think of doing in either way though.

Posted

I'm not sure how your data got to be 724188 bits if you only have 50 entries of 3 integers, so it could very well be something else going on.

 

At any rate, a normal packet should not have this restriction, if it is indeed some special restriction enforced on TileEntity description packets.

 

Another option is to find a more compact way of storing your data, rather than three keys per entry, you can do it in one using NBTTagCompound.setIntArray(String, int[]):

while (it.hasNext()) {
Entry<int[], Integer> entry = (Entry<int[], Integer>) it.next();
nbt.setIntArray("counter" + i, new int[] {((int[]) entry.getKey())[0], ((int[]) entry.getKey())[1], ((Integer) entry.getValue()).intValue()});
i++;
}

I'm sure there's a better way to write it without all those casts, but you get the idea.

Same as the answer above, but thanks fo the tip! :)

 

You should clear the "counter" map in #onDataPacket, before #readFromNBT.

counter.put(new int[] { id, damage }, Integer.valueOf(count));

Int arrays aren't good for keys in a map. They don't behave like you think they would.

Done,  thanks :)

I moved to creating a SortItem class for that now.

 

 

I will now try to send data via custom packets, only sent when opening a guy, I'll see if that helps :)

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.