So I am making a mod for Minecraft 1.6.4 running Forge #965 and i encountered the following problem:
In my Gui class im sending packets to the server to save changed settings. I've tested it and it ONLY sends 1 packet, but my packethandler receives always 2 packets. The 2 received packets seem to have the excact same data and all the values of the variables are the same. I think it automatically sends 2 packets to ensure that atleast 1 arrives, but how can I detect which packets are unneeded, cause the first ones arrived? Please help!
PacketHandlerASI.java:
<code>
@Override
public void onPacketData(INetworkManager parNetwordManager, Packet250CustomPayload parPacket, Player parPlayer) {
if(parPacket.channel != PACKET_CHANNEL) return;
EntityPlayer player = (EntityPlayer)parPlayer;
boolean isClient = player.worldObj.isRemote;
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(parPacket.data));
try {
byte packetID = inputStream.readByte();
if(packetID == PACKET_ID.OBJECTSORTER_GUI_SET.ID) {
handlePacketObjectSorterGuiSet(parNetwordManager, parPacket, parPlayer, player, inputStream, isClient);
}
else if(packetID == PACKET_ID.OBJECTSORTER_REQUEST.ID) {
handlePacketObjectSorterRequest(parNetwordManager, parPacket, parPlayer, player, inputStream, isClient);
}
}
catch(Exception e) {
e.printStackTrace();
System.err.println("An exception occured while processing the packet!");
}
}
</code>
GuiObjectSorter.java:
<code>
public void sendRequestToServer(int parType, int parSide) {
Packet250CustomPayload packet = new Packet250CustomPayload();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream packetOutput = new DataOutputStream(byteArrayOutputStream);
try {
packetOutput.writeByte(PacketHandlerASI.PACKET_ID.OBJECTSORTER_REQUEST.ID);
packetOutput.writeInt(tileEntity.xCoord);
packetOutput.writeInt(tileEntity.yCoord);
packetOutput.writeInt(tileEntity.zCoord);
packetOutput.writeByte((byte)((parType & 0xf) | ((parSide << 4) & 0xf0)));
}
catch(IOException e) {
e.printStackTrace();
}
packet.channel = PacketHandlerASI.PACKET_CHANNEL;
packet.data = byteArrayOutputStream.toByteArray();
packet.length = packet.data.length;
System.out.println("GuiObjectSorter.actionPerformed() > Sent packet to server!");
PacketDispatcher.sendPacketToServer(packet);
}
</code>