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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Minecraft 1.21.4 requires a new model definition file for each item, which you don't have. These can be created through Data Generation, specifically the ModelProvider, BlockModelGenerators and ItemModelGenerators classes.
    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
  • Topics

×
×
  • Create New...

Important Information

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