File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
src/main/java/net/hypixel/modapi/serializer Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -42,13 +42,20 @@ public int readVarInt() {
42
42
return i ;
43
43
}
44
44
45
- public void writeVarInt (int i ) {
46
- while ((i & -128 ) != 0 ) {
47
- this .buf .writeByte (i & 127 | 128 );
48
- i >>>= 7 ;
45
+ public PacketSerializer writeVarInt (int value ) {
46
+ if ((value & 0xFFFFFF80 ) == 0 ) {
47
+ buf .writeByte (value );
48
+ } else if ((value & 0xFFFFC000 ) == 0 ) {
49
+ buf .writeShort ((value & 0x7F | 0x80 ) << 8 | (value >>> 7 & 0x7F ));
50
+ } else if ((value & 0xFFE00000 ) == 0 ) {
51
+ buf .writeMedium ((value & 0x7F | 0x80 ) << 16 | (value >>> 7 & 0x7F | 0x80 ) << 8 | (value >>> 14 & 0x7F ));
52
+ } else if ((value & 0xF0000000 ) == 0 ) {
53
+ buf .writeInt ((value & 0x7F | 0x80 ) << 24 | (value >>> 7 & 0x7F | 0x80 ) << 16 | (value >>> 14 & 0x7F | 0x80 ) << 8 | (value >>> 21 & 0x7F ));
54
+ } else {
55
+ buf .writeInt ((value & 0x7F | 0x80 ) << 24 | (value >>> 7 & 0x7F | 0x80 ) << 16 | (value >>> 14 & 0x7F | 0x80 ) << 8 | (value >>> 21 & 0x7F | 0x80 ));
56
+ buf .writeByte (value >>> 28 );
49
57
}
50
-
51
- this .buf .writeByte (i );
58
+ return this ;
52
59
}
53
60
54
61
public String readString () {
You can’t perform that action at this time.
0 commit comments