PaperMC/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch
CraftBukkit/Spigot 43702a9e10 Update to Minecraft 1.18-pre5
By: md_5 <git@md-5.net>
2021-11-22 09:00:00 +11:00

92 lines
3.7 KiB
Diff

--- a/net/minecraft/network/PacketDataSerializer.java
+++ b/net/minecraft/network/PacketDataSerializer.java
@@ -54,6 +54,8 @@
import net.minecraft.world.phys.MovingObjectPositionBlock;
import net.minecraft.world.phys.Vec3D;
+import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
+
public class PacketDataSerializer extends ByteBuf {
private static final int MAX_VARINT_SIZE = 5;
@@ -122,7 +124,7 @@
public <T, C extends Collection<T>> C readCollection(IntFunction<C> intfunction, Function<PacketDataSerializer, T> function) {
int i = this.readVarInt();
- C c0 = (Collection) intfunction.apply(i);
+ C c0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
c0.add(function.apply(this));
@@ -133,7 +135,7 @@
public <T> void writeCollection(Collection<T> collection, BiConsumer<PacketDataSerializer, T> biconsumer) {
this.writeVarInt(collection.size());
- Iterator iterator = collection.iterator();
+ Iterator<T> iterator = collection.iterator(); // CraftBukkit - decompile error
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -144,7 +146,7 @@
}
public <T> List<T> readList(Function<PacketDataSerializer, T> function) {
- return (List) this.readCollection(Lists::newArrayListWithCapacity, function);
+ return (List) this.readCollection((java.util.function.IntFunction) Lists::newArrayListWithCapacity, function); // CraftBukkit - decompile error
}
public IntList readIntIdList() {
@@ -160,12 +162,12 @@
public void writeIntIdList(IntList intlist) {
this.writeVarInt(intlist.size());
- intlist.forEach(this::writeVarInt);
+ intlist.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error
}
public <K, V, M extends Map<K, V>> M readMap(IntFunction<M> intfunction, Function<PacketDataSerializer, K> function, Function<PacketDataSerializer, V> function1) {
int i = this.readVarInt();
- M m0 = (Map) intfunction.apply(i);
+ M m0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
K k0 = function.apply(this);
@@ -354,7 +356,7 @@
}
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
}
public PacketDataSerializer writeEnum(Enum<?> oenum) {
@@ -431,7 +433,7 @@
} else {
try {
NBTCompressedStreamTools.write(nbttagcompound, (DataOutput) (new ByteBufOutputStream(this)));
- } catch (IOException ioexception) {
+ } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception
throw new EncoderException(ioexception);
}
}
@@ -468,7 +470,7 @@
}
public PacketDataSerializer writeItem(ItemStack itemstack) {
- if (itemstack.isEmpty()) {
+ if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
this.writeBoolean(false);
} else {
this.writeBoolean(true);
@@ -497,6 +499,11 @@
ItemStack itemstack = new ItemStack(Item.byId(i), b0);
itemstack.setTag(this.readNbt());
+ // CraftBukkit start
+ if (itemstack.getTag() != null) {
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
+ }
+ // CraftBukkit end
return itemstack;
}
}