diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java index 6dd4c4eb4..8b10749e2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/Protocol1_11To1_10.java @@ -223,8 +223,9 @@ public class Protocol1_11To1_10 extends Protocol> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java index caad565a8..84cee1aeb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/BlockEntityProvider.java @@ -1,6 +1,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; @@ -8,7 +9,12 @@ import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.platform.providers.Provider; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BannerHandler; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BedHandler; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.CommandBlockHandler; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.FlowerPotHandler; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.SkullHandler; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.SpawnerHandler; import java.util.HashMap; import java.util.Map; @@ -36,10 +42,10 @@ public class BlockEntityProvider implements Provider { * @throws Exception Gotta throw that exception */ public int transform(UserConnection user, Position position, CompoundTag tag, boolean sendUpdate) throws Exception { - if (!tag.contains("id")) - return -1; + Tag idTag = tag.get("id"); + if (idTag == null) return -1; - String id = (String) tag.get("id").getValue(); + String id = (String) idTag.getValue(); BlockEntityHandler handler = handlers.get(id); if (handler == null) { if (Via.getManager().isDebug()) { @@ -50,8 +56,9 @@ public class BlockEntityProvider implements Provider { int newBlock = handler.transform(user, tag); - if (sendUpdate && newBlock != -1) + if (sendUpdate && newBlock != -1) { sendBlockChange(user, position, newBlock); + } return newBlock; } @@ -67,6 +74,4 @@ public class BlockEntityProvider implements Provider { public interface BlockEntityHandler { int transform(UserConnection user, CompoundTag tag); } - - } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java index 412028944..4e13a5e7f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java @@ -23,7 +23,6 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { } int id = storage.get(position).getOriginal(); - if (id >= SKULL_WALL_START && id <= SKULL_END) { Tag skullType = tag.get("SkullType"); if (skullType != null) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java index 8df3e45d2..1fd966184 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java @@ -5,6 +5,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.protocol.Protocol; @@ -69,42 +70,58 @@ public class WorldPackets { if (chunk.getBlockEntities() == null) return; for (CompoundTag blockEntity : chunk.getBlockEntities()) { - StringTag idTag = blockEntity.get("id"); - if (idTag == null) continue; - - String id = idTag.getValue(); - if (id.equals("minecraft:conduit")) { - StringTag targetUuidTag = blockEntity.remove("target_uuid"); - if (targetUuidTag == null) continue; - - // target_uuid -> Target - UUID targetUuid = UUID.fromString(targetUuidTag.getValue()); - blockEntity.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid))); - } else if (id.equals("minecraft:skull") && blockEntity.get("Owner") instanceof CompoundTag) { - CompoundTag ownerTag = blockEntity.remove("Owner"); - StringTag ownerUuidTag = ownerTag.remove("Id"); - if (ownerUuidTag != null) { - UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue()); - ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); - } - - // Owner -> SkullOwner - CompoundTag skullOwnerTag = new CompoundTag("SkullOwner"); - for (Tag tag : ownerTag) { - skullOwnerTag.put(tag); - } - blockEntity.put(skullOwnerTag); - } + handleBlockEntity(blockEntity); } }); } }); + protocol.registerOutgoing(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + Position position = wrapper.passthrough(Type.POSITION1_14); + short action = wrapper.passthrough(Type.UNSIGNED_BYTE); + CompoundTag tag = wrapper.passthrough(Type.NBT); + handleBlockEntity(tag); + }); + } + }); + blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32, WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); } + private static void handleBlockEntity(CompoundTag compoundTag) { + StringTag idTag = compoundTag.get("id"); + if (idTag == null) return; + + String id = idTag.getValue(); + if (id.equals("minecraft:conduit")) { + StringTag targetUuidTag = compoundTag.remove("target_uuid"); + if (targetUuidTag == null) return; + + // target_uuid -> Target + UUID targetUuid = UUID.fromString(targetUuidTag.getValue()); + compoundTag.put(new IntArrayTag("Target", UUIDIntArrayType.uuidToIntArray(targetUuid))); + } else if (id.equals("minecraft:skull") && compoundTag.get("Owner") instanceof CompoundTag) { + CompoundTag ownerTag = compoundTag.remove("Owner"); + StringTag ownerUuidTag = ownerTag.remove("Id"); + if (ownerUuidTag != null) { + UUID ownerUuid = UUID.fromString(ownerUuidTag.getValue()); + ownerTag.put(new IntArrayTag("Id", UUIDIntArrayType.uuidToIntArray(ownerUuid))); + } + + // Owner -> SkullOwner + CompoundTag skullOwnerTag = new CompoundTag("SkullOwner"); + for (Tag tag : ownerTag) { + skullOwnerTag.put(tag); + } + compoundTag.put(skullOwnerTag); + } + } + public static int getNewParticleId(int id) { if (id >= 27) { id += 2; // soul flame, soul