I don;t have a really GOOD idea of what I'm doing... so I wouldn't be surprised if I'm doing a lot wrong. like assuming every little thing you do can only be on per packet. But heres the error I keep getting.
Caused by: java.lang.IndexOutOfBoundsException: readerIndex(0) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 0, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1160) ~[AbstractByteBuf.class:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:611) ~[AbstractByteBuf.class:?]
at doop.BLPacket.fromBytes(BLPacket.java:27) ~[BLPacket.class:?]
public class packet{
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(com.Maddoctor.MedimodMaddoctor.MODID);
}
Here's how I register all my packets in my common class.
public void load(FMLInitializationEvent event) {
int packetIdLG = 0;
int packetIdIT = 1;
int packetIdBL = 2;
int packetIdCH = 3;
int packetIdIO = 4;
int packetIdOK = 5;
int packetIdSH = 6;
int packetIdTH = 7;
int packetIdCA = 8;
int packetIdDA = 9;
doop.packet.INSTANCE.registerMessage(THHandler.class, THPacket.class, packetIdTH++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(BLHandler.class, BLPacket.class, packetIdBL++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(CAHandler.class, CAPacket.class, packetIdCA++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(LGHandler.class, LGPacket.class, packetIdLG++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(CHHandler.class, CHPacket.class, packetIdCH++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(DAHandler.class, DAPacket.class, packetIdDA++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(IOHandler.class, IOPacket.class, packetIdIO++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(ITHandler.class, ITpacket.class, packetIdIT++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(OKHandler.class, OKPacket.class, packetIdOK++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(SHHandler.class, SHPacket.class, packetIdSH++, Side.SERVER);
}
And here's the packet in the error message but their all REALLY similar. I mean they all do different stuff but their around the same size ish..
public class BLPacket implements cpw.mods.fml.common.network.simpleimpl.IMessage {
private int B;
@Override
public void fromBytes(ByteBuf buf) {
this.B = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeByte(this.B);
public static class BLHandler implements IMessageHandler<BLPacket, IMessage> {
@Override public IMessage onMessage(BLPacket msg, MessageContext ctx) {
// This is the player the packet was sent to the server from
EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;
// The value that was sent
int N = msg.B;
PlayerData.get(serverPlayer).SetBlutz(N);
// No response packet
return null;
}
}
}
Sorry if this isn't a well organized request for help, I don't know what I'm doing all that well....
Thanks in advance.
@Override
public void fromBytes(ByteBuf buf) {
this.B = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeByte(this.B);
}
This is your error. You're writing a byte but reading an int, and they are very different when every binary bit counts.
Since this.B is of type int, you should use ByteBufUtils.writeVarInt(buf, this.B, 5) and ByteBufUtils.readVarInt(buf, 5) . The last parameter (5 in my example) represents how many bits (and thus the max size) you can write, and you might be safe passing 3 or 4, depending on how large you expect the int to be. Just make sure that both read and write use the same number.
Edit: also, your packet registration is very inefficient. The whole point of using variableName++ is so you only need one variable and it is guaranteed to be different each time.
Remove all but one of the packetIdXX and use just that one for every packet (using the ++ of course)
One more note: if all your packets are very similar, why do you need more than one? At the very least you could use a base class for the variables and read/write, then just have different handlers...
I don;t have a really GOOD idea of what I'm doing... so I wouldn't be surprised if I'm doing a lot wrong. like assuming every little thing you do can only be on per packet. But heres the error I keep getting.
Caused by: java.lang.IndexOutOfBoundsException: readerIndex(0) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 0, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1160) ~[AbstractByteBuf.class:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:611) ~[AbstractByteBuf.class:?]
at doop.BLPacket.fromBytes(BLPacket.java:27) ~[BLPacket.class:?]
Heres my, Packet instance? Class
package doop;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
public class packet{
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(com.Maddoctor.MedimodMaddoctor.MODID);
}
Here's how I register all my packets in my common class.
public void load(FMLInitializationEvent event) {
int packetIdLG = 0;
int packetIdIT = 1;
int packetIdBL = 2;
int packetIdCH = 3;
int packetIdIO = 4;
int packetIdOK = 5;
int packetIdSH = 6;
int packetIdTH = 7;
int packetIdCA = 8;
int packetIdDA = 9;
doop.packet.INSTANCE.registerMessage(THHandler.class, THPacket.class, packetIdTH++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(BLHandler.class, BLPacket.class, packetIdBL++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(CAHandler.class, CAPacket.class, packetIdCA++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(LGHandler.class, LGPacket.class, packetIdLG++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(CHHandler.class, CHPacket.class, packetIdCH++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(DAHandler.class, DAPacket.class, packetIdDA++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(IOHandler.class, IOPacket.class, packetIdIO++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(ITHandler.class, ITpacket.class, packetIdIT++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(OKHandler.class, OKPacket.class, packetIdOK++, Side.SERVER);
doop.packet.INSTANCE.registerMessage(SHHandler.class, SHPacket.class, packetIdSH++, Side.SERVER);
}
And here's the packet in the error message but their all REALLY similar. I mean they all do different stuff but their around the same size ish..
public class BLPacket implements cpw.mods.fml.common.network.simpleimpl.IMessage {
private int B;
@Override
public void fromBytes(ByteBuf buf) {
this.B = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeByte(this.B);
}
public BLPacket() {}
public BLPacket(int BO) {
this.B = BO;
}
// =========================================================================
public static class BLHandler implements IMessageHandler<BLPacket, IMessage> {
@Override public IMessage onMessage(BLPacket msg, MessageContext ctx) {
// This is the player the packet was sent to the server from
EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;
// The value that was sent
int N = msg.B;
PlayerData.get(serverPlayer).SetBlutz(N);
// No response packet
return null;
}
}
}
Sorry if this isn't a well organized request for help, I don't know what I'm doing all that well....
Thanks in advance.
This is your error. You're writing a byte but reading an int, and they are very different when every binary bit counts.
Since this.B is of type int, you should use ByteBufUtils.writeVarInt(buf, this.B, 5) and ByteBufUtils.readVarInt(buf, 5) . The last parameter (5 in my example) represents how many bits (and thus the max size) you can write, and you might be safe passing 3 or 4, depending on how large you expect the int to be. Just make sure that both read and write use the same number.
Read more about packets here.
Edit: also, your packet registration is very inefficient. The whole point of using variableName++ is so you only need one variable and it is guaranteed to be different each time.
Remove all but one of the packetIdXX and use just that one for every packet (using the ++ of course)
One more note: if all your packets are very similar, why do you need more than one? At the very least you could use a base class for the variables and read/write, then just have different handlers...
"You're writing[/b] a byte[/b] but reading[/b] an int[/b],"

DOH!
Would you believe I've done that twice now? XD
And that shouldn't be a problem, all this packet does is resets the int on the server side, back to 0.
Thanks alot