mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 04:27:59 +01:00
Add version signature to packet data (#223)
This commit is contained in:
parent
1b0f2660f9
commit
42d45b3a9e
1 changed files with 20 additions and 0 deletions
|
@ -17,6 +17,10 @@ import java.util.function.Supplier;
|
|||
|
||||
public class MsgPonyData implements IPonyData {
|
||||
|
||||
private final short API_IDENTIFIER = (short) 0xABCD;
|
||||
// API version - increment this number before any time any data is added/removed/moved in the data stream
|
||||
private final byte API_VERSION = 2;
|
||||
|
||||
private final Race race;
|
||||
private final TailLength tailLength;
|
||||
private final TailShape tailShape;
|
||||
|
@ -41,6 +45,19 @@ public class MsgPonyData implements IPonyData {
|
|||
}
|
||||
|
||||
public MsgPonyData(PacketByteBuf buffer) {
|
||||
short data = buffer.readShort();
|
||||
if (data != API_IDENTIFIER || buffer.readByte() != API_VERSION) {
|
||||
race = null;
|
||||
tailLength = null;
|
||||
tailShape = null;
|
||||
gender = null;
|
||||
size = null;
|
||||
glowColor = 0;
|
||||
noSkin = true;
|
||||
wearables = null;
|
||||
wearableColor = 0;
|
||||
return;
|
||||
}
|
||||
race = buffer.readEnumConstant(Race.class);
|
||||
tailLength = buffer.readEnumConstant(TailLength.class);
|
||||
tailShape = buffer.readEnumConstant(TailShape.class);
|
||||
|
@ -70,6 +87,9 @@ public class MsgPonyData implements IPonyData {
|
|||
}
|
||||
|
||||
public PacketByteBuf toBuffer(PacketByteBuf buffer) {
|
||||
buffer.writeByte((API_IDENTIFIER & 0xFF00) >> 8);
|
||||
buffer.writeByte(API_IDENTIFIER & 0x00FF);
|
||||
buffer.writeByte(API_VERSION);
|
||||
buffer.writeEnumConstant(race);
|
||||
buffer.writeEnumConstant(tailLength);
|
||||
buffer.writeEnumConstant(tailShape);
|
||||
|
|
Loading…
Reference in a new issue