Skip to content

Commit ececd96

Browse files
committed
Workaround pre 1.16.2 MC-68487
Fixes #255
1 parent e9ace2d commit ececd96

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings;
77
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
88
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord1_8;
9+
import us.myles.ViaVersion.api.minecraft.Position;
910
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
1011
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
1112
import us.myles.ViaVersion.api.remapper.PacketRemapper;
@@ -18,6 +19,12 @@
1819
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
1920
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
2021
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
22+
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
23+
import us.myles.viaversion.libs.opennbt.tag.builtin.IntArrayTag;
24+
import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag;
25+
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
26+
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
27+
import us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
2128

2229
public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> {
2330

@@ -78,6 +85,29 @@ public void registerMap() {
7885
section.setPaletteEntry(j, Protocol1_16_1To1_16_2.getNewBlockStateId(old));
7986
}
8087
}
88+
89+
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
90+
if (blockEntity == null) continue;
91+
92+
IntTag x = blockEntity.get("x");
93+
IntTag y = blockEntity.get("y");
94+
IntTag z = blockEntity.get("z");
95+
96+
if (x != null && y != null && z != null) {
97+
handleBlockEntity(blockEntity, new Position(x.getValue(), y.getValue().shortValue(), z.getValue()));
98+
}
99+
}
100+
});
101+
}
102+
});
103+
104+
protocol.registerOutgoing(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() {
105+
@Override
106+
public void registerMap() {
107+
handler(wrapper -> {
108+
Position position = wrapper.passthrough(Type.POSITION1_14);
109+
wrapper.passthrough(Type.UNSIGNED_BYTE);
110+
handleBlockEntity(wrapper.passthrough(Type.NBT), position);
81111
});
82112
}
83113
});
@@ -121,6 +151,33 @@ public void registerMap() {
121151
});
122152
}
123153

154+
private void handleBlockEntity(CompoundTag tag, Position position) {
155+
StringTag idTag = tag.get("id");
156+
if (idTag == null) return;
157+
if (idTag.getValue().equals("minecraft:skull")) {
158+
// Workaround an old client bug: MC-68487
159+
Tag skullOwnerTag = tag.get("SkullOwner");
160+
if (!(skullOwnerTag instanceof CompoundTag)) return;
161+
162+
CompoundTag skullOwnerCompoundTag = (CompoundTag) skullOwnerTag;
163+
if (!skullOwnerCompoundTag.contains("Id")) return;
164+
165+
CompoundTag properties = skullOwnerCompoundTag.get("Properties");
166+
if (properties == null) return;
167+
168+
ListTag textures = properties.get("textures");
169+
if (textures == null) return;
170+
171+
CompoundTag first = textures.size() > 0 ? textures.get(0) : null;
172+
if (first == null) return;
173+
174+
// Make the client cache the skinprofile over this uuid
175+
int hashCode = first.get("Value").getValue().hashCode();
176+
int[] uuidIntArray = {hashCode, 0, 0, 0}; //TODO split texture in 4 for a lower collision chance
177+
skullOwnerCompoundTag.put(new IntArrayTag("Id", uuidIntArray));
178+
}
179+
}
180+
124181
public static int getNewItemId(int id) {
125182
int newId = MappingData.oldToNewItems.get(id);
126183
if (newId == -1) {

0 commit comments

Comments
 (0)