2021-03-15 23:00:00 +01:00
--- a/net/minecraft/network/PacketDataSerializer.java
+++ b/net/minecraft/network/PacketDataSerializer.java
2023-03-14 17:30:00 +01:00
@@ -81,6 +81,8 @@
import org.joml.Quaternionf;
import org.joml.Vector3f;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
+
public class PacketDataSerializer extends ByteBuf {
2021-06-11 07:00:00 +02:00
private static final int MAX_VARINT_SIZE = 5;
2023-03-14 17:30:00 +01:00
@@ -220,7 +222,7 @@
2021-06-11 07:00:00 +02:00
2022-06-07 18:00:00 +02:00
public <T, C extends Collection<T>> C readCollection(IntFunction<C> intfunction, PacketDataSerializer.a<T> packetdataserializer_a) {
2021-11-21 23:00:00 +01:00
int i = this.readVarInt();
2021-06-11 07:00:00 +02:00
- C c0 = (Collection) intfunction.apply(i);
+ C c0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
2022-06-07 18:00:00 +02:00
c0.add(packetdataserializer_a.apply(this));
2023-03-14 17:30:00 +01:00
@@ -231,7 +233,7 @@
2021-06-11 07:00:00 +02:00
2022-06-07 18:00:00 +02:00
public <T> void writeCollection(Collection<T> collection, PacketDataSerializer.b<T> packetdataserializer_b) {
2021-11-21 23:00:00 +01:00
this.writeVarInt(collection.size());
2021-06-11 07:00:00 +02:00
- Iterator iterator = collection.iterator();
+ Iterator<T> iterator = collection.iterator(); // CraftBukkit - decompile error
while (iterator.hasNext()) {
T t0 = iterator.next();
2023-03-14 17:30:00 +01:00
@@ -258,12 +260,12 @@
2021-06-11 07:00:00 +02:00
2021-11-21 23:00:00 +01:00
public void writeIntIdList(IntList intlist) {
this.writeVarInt(intlist.size());
- intlist.forEach(this::writeVarInt);
+ intlist.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error
2021-06-11 07:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
public <K, V, M extends Map<K, V>> M readMap(IntFunction<M> intfunction, PacketDataSerializer.a<K> packetdataserializer_a, PacketDataSerializer.a<V> packetdataserializer_a1) {
2021-11-21 23:00:00 +01:00
int i = this.readVarInt();
2021-06-11 07:00:00 +02:00
- M m0 = (Map) intfunction.apply(i);
+ M m0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
2022-06-07 18:00:00 +02:00
K k0 = packetdataserializer_a.apply(this);
2023-03-14 17:30:00 +01:00
@@ -297,7 +299,7 @@
2022-12-07 17:00:00 +01:00
}
public <E extends Enum<E>> void writeEnumSet(EnumSet<E> enumset, Class<E> oclass) {
- E[] ae = (Enum[]) oclass.getEnumConstants();
+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error
BitSet bitset = new BitSet(ae.length);
for (int i = 0; i < ae.length; ++i) {
2023-03-14 17:30:00 +01:00
@@ -308,7 +310,7 @@
2022-12-07 17:00:00 +01:00
}
public <E extends Enum<E>> EnumSet<E> readEnumSet(Class<E> oclass) {
- E[] ae = (Enum[]) oclass.getEnumConstants();
+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error
BitSet bitset = this.readFixedBitSet(ae.length);
EnumSet<E> enumset = EnumSet.noneOf(oclass);
2023-03-14 17:30:00 +01:00
@@ -545,7 +547,7 @@
2015-02-26 23:41:06 +01:00
}
2021-11-21 23:00:00 +01:00
public <T extends Enum<T>> T readEnum(Class<T> oclass) {
- return ((Enum[]) oclass.getEnumConstants())[this.readVarInt()];
+ return ((T[]) oclass.getEnumConstants())[this.readVarInt()]; // CraftBukkit - fix decompile error
2015-02-26 23:41:06 +01:00
}
2021-11-21 23:00:00 +01:00
public PacketDataSerializer writeEnum(Enum<?> oenum) {
2023-03-14 17:30:00 +01:00
@@ -622,7 +624,7 @@
2014-11-25 22:32:16 +01:00
} else {
try {
2021-11-21 23:00:00 +01:00
NBTCompressedStreamTools.write(nbttagcompound, (DataOutput) (new ByteBufOutputStream(this)));
2014-11-25 22:32:16 +01:00
- } catch (IOException ioexception) {
+ } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception
throw new EncoderException(ioexception);
}
}
2023-03-14 17:30:00 +01:00
@@ -659,7 +661,7 @@
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
public PacketDataSerializer writeItem(ItemStack itemstack) {
2016-11-17 02:41:03 +01:00
- if (itemstack.isEmpty()) {
+ if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
2018-10-22 21:00:00 +02:00
this.writeBoolean(false);
2014-11-25 22:32:16 +01:00
} else {
2018-10-22 21:00:00 +02:00
this.writeBoolean(true);
2023-03-14 17:30:00 +01:00
@@ -688,6 +690,11 @@
2022-06-07 18:00:00 +02:00
ItemStack itemstack = new ItemStack(item, b0);
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
itemstack.setTag(this.readNbt());
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ if (itemstack.getTag() != null) {
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
return itemstack;
2014-11-25 22:32:16 +01:00
}
2016-11-17 02:41:03 +01:00
}