|
6 | 6 | import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings; |
7 | 7 | import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; |
8 | 8 | import us.myles.ViaVersion.api.minecraft.BlockChangeRecord1_8; |
| 9 | +import us.myles.ViaVersion.api.minecraft.Position; |
9 | 10 | import us.myles.ViaVersion.api.minecraft.chunks.Chunk; |
10 | 11 | import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; |
11 | 12 | import us.myles.ViaVersion.api.remapper.PacketRemapper; |
|
18 | 19 | import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; |
19 | 20 | import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; |
20 | 21 | 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; |
21 | 28 |
|
22 | 29 | public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> { |
23 | 30 |
|
@@ -78,6 +85,29 @@ public void registerMap() { |
78 | 85 | section.setPaletteEntry(j, Protocol1_16_1To1_16_2.getNewBlockStateId(old)); |
79 | 86 | } |
80 | 87 | } |
| 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); |
81 | 111 | }); |
82 | 112 | } |
83 | 113 | }); |
@@ -121,6 +151,33 @@ public void registerMap() { |
121 | 151 | }); |
122 | 152 | } |
123 | 153 |
|
| 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 | + |
124 | 181 | public static int getNewItemId(int id) { |
125 | 182 | int newId = MappingData.oldToNewItems.get(id); |
126 | 183 | if (newId == -1) { |
|
0 commit comments