Paper/patches/server/0242-Fix-client-rendering-skulls-from-same-user.patch

132 Zeilen
6.8 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 22 Nov 2016 00:40:42 -0500
Subject: [PATCH] Fix client rendering skulls from same user
See: https://github.com/PaperMC/Paper/issues/1304
Changes the UUID sent to client to be based on either
the texture payload, or random.
This allows the client to render multiple skull textures from the same user,
for when different skins were used when skull was made.
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2021-06-13 01:45:00 +02:00
index c0966a873ea5e265936e17796bf6bbee62eea9b4..813814a09ad4c8040d9bf7fff12c8c7b88f164c2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2021-06-13 01:45:00 +02:00
@@ -473,9 +473,18 @@ public class FriendlyByteBuf extends ByteBuf {
2021-06-11 14:02:28 +02:00
if (item.canBeDepleted() || item.shouldOverrideMultiplayerNbt()) {
// Spigot start - filter
2021-06-13 01:45:00 +02:00
stack = stack.copy();
- CraftItemStack.setItemMeta(stack, CraftItemStack.getItemMeta(stack));
+ // CraftItemStack.setItemMeta(stack, CraftItemStack.getItemMeta(stack)); // Paper - This is no longer needed due to NBT being supported
2021-06-11 14:02:28 +02:00
// Spigot end
2021-06-13 01:45:00 +02:00
nbttagcompound = stack.getTag();
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (nbttagcompound != null && nbttagcompound.contains("SkullOwner", 10)) {
+ CompoundTag owner = nbttagcompound.getCompound("SkullOwner");
+ if (owner.hasUUID("Id")) {
+ nbttagcompound.setUUID("SkullOwnerOrig", owner.getUUID("Id"));
2021-06-13 01:45:00 +02:00
+ net.minecraft.world.level.block.entity.SkullBlockEntity.sanitizeUUID(owner);
2021-06-11 14:02:28 +02:00
+ }
+ }
+ // Paper end
}
this.writeNbt(nbttagcompound);
2021-06-13 01:45:00 +02:00
@@ -495,7 +504,16 @@ public class FriendlyByteBuf extends ByteBuf {
2021-06-11 14:02:28 +02:00
itemstack.setTag(this.readNbt());
// CraftBukkit start
if (itemstack.getTag() != null) {
- CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
+ // Paper start - Fix skulls of same owner - restore orig ID since we changed it on send to client
+ if (itemstack.tag.contains("SkullOwnerOrig")) {
+ CompoundTag owner = itemstack.tag.getCompound("SkullOwner");
+ if (itemstack.tag.contains("SkullOwnerOrig")) {
+ owner.tags.put("Id", itemstack.tag.tags.get("SkullOwnerOrig"));
+ itemstack.tag.remove("SkullOwnerOrig");
+ }
+ }
+ // Paper end
+ // CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack)); // Paper - This is no longer needed due to NBT being supported
}
// CraftBukkit end
return itemstack;
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacket.java
2021-06-13 01:45:00 +02:00
index 3bdb09ab00ec05ed532a0c26b9fd321e1f05c1a0..1451a98d69b185dd15a2d1d7681bcecb6a4f99c1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundLevelChunkPacket.java
2021-06-13 01:45:00 +02:00
@@ -48,6 +48,7 @@ public class ClientboundLevelChunkPacket implements Packet<ClientGamePacketListe
for(Entry<BlockPos, BlockEntity> entry2 : chunk.getBlockEntities().entrySet()) {
BlockEntity blockEntity = entry2.getValue();
CompoundTag compoundTag = blockEntity.getUpdateTag();
+ if (blockEntity instanceof net.minecraft.world.level.block.entity.SkullBlockEntity) { net.minecraft.world.level.block.entity.SkullBlockEntity.sanitizeTileEntityUUID(compoundTag); } // Paper
this.blockEntitiesTags.add(compoundTag);
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
2021-06-13 01:45:00 +02:00
index 4d4b471bbfb2d9174391c8adc6075ec11295408b..8b3cf3b882ea6c0d48df8b551f4b85b87b889c58 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
2021-06-13 01:45:00 +02:00
@@ -143,7 +143,7 @@ public final class ItemStack {
2021-06-11 14:02:28 +02:00
private int popTime;
@Deprecated
private Item item;
- private CompoundTag tag;
+ public CompoundTag tag; // Paper private -> public
private boolean emptyCacheFlag;
private Entity entityRepresentation;
private BlockInWorld cachedBreakBlock;
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2021-06-13 01:45:00 +02:00
index eaf586eb386e13e954bc593f6ddbc45929cec204..f0192a009f6a21d1781ce709624a9187048d9a08 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
2021-06-13 01:45:00 +02:00
@@ -10,6 +10,7 @@ import java.util.function.Consumer;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
2021-06-11 14:02:28 +02:00
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
2021-06-13 01:45:00 +02:00
import net.minecraft.server.players.GameProfileCache;
@@ -91,9 +92,37 @@ public class SkullBlockEntity extends BlockEntity {
2021-06-11 14:02:28 +02:00
@Nullable
@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
- return new ClientboundBlockEntityDataPacket(this.worldPosition, 4, this.getUpdateTag());
+ return new ClientboundBlockEntityDataPacket(this.worldPosition, 4, sanitizeTileEntityUUID(this.getUpdateTag())); // Paper
}
+ // Paper start
+ public static CompoundTag sanitizeTileEntityUUID(CompoundTag cmp) {
+ CompoundTag owner = cmp.getCompound("Owner");
+ if (!owner.isEmpty()) {
+ sanitizeUUID(owner);
+ }
+ return cmp;
+ }
+
+ public static void sanitizeUUID(CompoundTag owner) {
+ CompoundTag properties = owner.getCompound("Properties");
+ ListTag list = null;
+ if (!properties.isEmpty()) {
+ list = properties.getList("textures", 10);
+ }
+
+ if (list != null && !list.isEmpty()) {
+ String textures = ((CompoundTag)list.get(0)).getString("Value");
+ if (textures != null && textures.length() > 3) {
+ UUID uuid = UUID.nameUUIDFromBytes(textures.getBytes());
+ owner.setUUID("Id", uuid);
+ return;
+ }
+ }
+ owner.setUUID("Id", UUID.randomUUID());
+ }
+ // Paper end
+
@Override
public CompoundTag getUpdateTag() {
return this.save(new CompoundTag());