From bd4df2813d52e77dd7174ce353761283079745e8 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 11 May 2024 23:06:29 +0200 Subject: [PATCH] Refactor protocols to match template module (#3842) --- .../v1_10to1_11/Protocol1_10To1_11.java | 128 +--------- .../BlockEntityNames1_11.java} | 4 +- .../EntityNames1_11.java} | 4 +- ...olorMapping.java => PotionColors1_11.java} | 2 +- .../EntityPacketRewriter1_11.java} | 127 +++++++++- .../rewriter/ItemPacketRewriter1_11.java | 16 +- .../v1_11_1to1_12/Protocol1_11_1To1_12.java | 51 +--- ....java => AchievementTranslations1_12.java} | 2 +- .../{rewriter => data}/ChatItemRewriter.java | 2 +- .../{rewriter => data}/TranslateRewriter.java | 9 +- .../MetadataRewriter1_12To1_11_1.java | 53 ---- .../rewriter/EntityPacketRewriter1_12.java | 96 ++++++++ .../v1_12_2to1_13/Protocol1_12_2To1_13.java | 9 +- .../MetadataRewriter1_13To1_12_2.java | 110 --------- .../rewriter/EntityPacketRewriter1_13.java | 102 +++++++- .../v1_13_2to1_14/Protocol1_13_2To1_14.java | 15 +- .../MetadataRewriter1_14To1_13_2.java | 231 ------------------ .../rewriter/EntityPacketRewriter1_14.java | 228 +++++++++++++++-- ..._14.java => PlayerPacketRewriter1_14.java} | 4 +- .../v1_13to1_13_1/Protocol1_13To1_13_1.java | 7 +- .../MetadataRewriter1_13_1To1_13.java | 52 ---- .../rewriter/EntityPacketRewriter1_13_1.java | 41 +++- .../v1_14_4to1_15/Protocol1_14_4To1_15.java | 11 +- .../MetadataRewriter1_15To1_14_4.java | 55 ----- .../rewriter/EntityPacketRewriter1_15.java | 53 ++-- .../v1_14to1_14_1/Protocol1_14To1_14_1.java | 11 +- .../MetadataRewriter1_14_1To1_14.java | 42 ---- .../rewriter/EntityPacketRewriter1_14_1.java | 32 ++- .../v1_15_2to1_16/Protocol1_15_2To1_16.java | 17 +- ...ibuteMappings.java => Attributes1_16.java} | 2 +- .../data/DimensionRegistries1_16.java | 119 +++++++++ .../MetadataRewriter1_16To1_15_2.java | 59 ----- .../ComponentRewriter1_16.java} | 6 +- .../rewriter/EntityPacketRewriter1_16.java | 144 ++++------- .../rewriter/ItemPacketRewriter1_16.java | 7 +- .../Protocol1_16_1To1_16_2.java | 11 +- .../MetadataRewriter1_16_2To1_16_1.java | 58 ----- .../rewriter/EntityPacketRewriter1_16_2.java | 55 ++++- ...ckEntities.java => BlockEntities1_18.java} | 2 +- ...EntityIds.java => BlockEntityIds1_18.java} | 2 +- .../rewriter/WorldPacketRewriter1_18.java | 9 +- .../v1_18_2to1_19/Protocol1_18_2To1_19.java | 7 +- .../storage/DimensionRegistryStorage.java | 2 +- ...onceStorage.java => NonceStorage1_19.java} | 2 +- .../Protocol1_19_1To1_19_3.java | 8 +- ...ceStorage.java => NonceStorage1_19_3.java} | 2 +- .../v1_19to1_19_1/Protocol1_19To1_19_1.java | 15 +- ...tRegistry.java => ChatRegistry1_19_1.java} | 2 +- ...ceStorage.java => NonceStorage1_19_1.java} | 2 +- 49 files changed, 914 insertions(+), 1114 deletions(-) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/{rewriter/BlockEntityRewriter.java => data/BlockEntityNames1_11.java} (96%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/{rewriter/EntityIdRewriter.java => data/EntityNames1_11.java} (98%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/{PotionColorMapping.java => PotionColors1_11.java} (98%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/{metadata/MetadataRewriter1_11.java => rewriter/EntityPacketRewriter1_11.java} (63%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/{AchievementTranslationMapping.java => AchievementTranslations1_12.java} (99%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/{rewriter => data}/ChatItemRewriter.java (96%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/{rewriter => data}/TranslateRewriter.java (93%) delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/metadata/MetadataRewriter1_12To1_11_1.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/EntityPacketRewriter1_12.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/metadata/MetadataRewriter1_13To1_12_2.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/metadata/MetadataRewriter1_14To1_13_2.java rename common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/{PlayerPackets1_14.java => PlayerPacketRewriter1_14.java} (98%) delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/metadata/MetadataRewriter1_13_1To1_13.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/metadata/MetadataRewriter1_15To1_14_4.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/metadata/MetadataRewriter1_14_1To1_14.java rename common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/{AttributeMappings.java => Attributes1_16.java} (98%) create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/DimensionRegistries1_16.java delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/metadata/MetadataRewriter1_16To1_15_2.java rename common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/{data/TranslationMappings.java => rewriter/ComponentRewriter1_16.java} (95%) delete mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/metadata/MetadataRewriter1_16_2To1_16_1.java rename common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/{BlockEntities.java => BlockEntities1_18.java} (98%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/{BlockEntityIds.java => BlockEntityIds1_18.java} (97%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/{NonceStorage.java => NonceStorage1_19.java} (92%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/{NonceStorage.java => NonceStorage1_19_3.java} (92%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/{ChatRegistry.java => ChatRegistry1_19_1.java} (97%) rename common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/{NonceStorage.java => NonceStorage1_19_1.java} (91%) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/Protocol1_10To1_11.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/Protocol1_10To1_11.java index 992934c7b..2eb156926 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/Protocol1_10To1_11.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/Protocol1_10To1_11.java @@ -28,14 +28,13 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; import com.viaversion.viaversion.api.type.types.version.Types1_9; -import com.viaversion.viaversion.protocols.v1_10to1_11.data.PotionColorMapping; -import com.viaversion.viaversion.protocols.v1_10to1_11.metadata.MetadataRewriter1_11; -import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.BlockEntityRewriter; -import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.PotionColors1_11; +import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityPacketRewriter1_11; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.BlockEntityNames1_11; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11; import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.ItemPacketRewriter1_11; import com.viaversion.viaversion.protocols.v1_10to1_11.storage.EntityTracker1_11; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; @@ -51,7 +50,7 @@ public class Protocol1_10To1_11 extends AbstractProtocol { - int entityId = wrapper.get(Types.VAR_INT, 0); - // Change Type :) - int type = wrapper.get(Types.VAR_INT, 1); - - EntityTypes1_11.EntityType entType = MetadataRewriter1_11.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0)); - if (entType != null) { - wrapper.set(Types.VAR_INT, 1, entType.getId()); - - // Register Type ID - wrapper.user().getEntityTracker(Protocol1_10To1_11.class).addEntity(entityId, entType); - entityRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user()); - } - }); - } - }); - new SoundRewriter<>(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND); - registerClientbound(ClientboundPackets1_9_3.TAKE_ITEM_ENTITY, new PacketHandlers() { - @Override - public void register() { - map(Types.VAR_INT); // 0 - Collected entity id - map(Types.VAR_INT); // 1 - Collector entity id - - handler(wrapper -> { - wrapper.write(Types.VAR_INT, 1); // 2 - Pickup Count - }); - } - }); - - entityRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.METADATA_LIST); - - registerClientbound(ClientboundPackets1_9_3.TELEPORT_ENTITY, new PacketHandlers() { - @Override - public void register() { - map(Types.VAR_INT); // 0 - Entity id - map(Types.DOUBLE); // 1 - x - map(Types.DOUBLE); // 2 - y - map(Types.DOUBLE); // 3 - z - map(Types.BYTE); // 4 - yaw - map(Types.BYTE); // 5 - pitch - map(Types.BOOLEAN); // 6 - onGround - - handler(wrapper -> { - int entityID = wrapper.get(Types.VAR_INT, 0); - if (Via.getConfig().isHologramPatch()) { - EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_10To1_11.class); - if (tracker.isHologram(entityID)) { - Double newValue = wrapper.get(Types.DOUBLE, 1); - newValue -= (Via.getConfig().getHologramYOffset()); - wrapper.set(Types.DOUBLE, 1, newValue); - } - } - }); - } - }); - - entityRewriter.registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES); - registerClientbound(ClientboundPackets1_9_3.SET_TITLES, new PacketHandlers() { @Override public void register() { @@ -187,28 +99,6 @@ public class Protocol1_10To1_11 extends AbstractProtocol { - CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0); - if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 1) { - EntityIdRewriter.toClientSpawner(tag); - } - - StringTag idTag = tag.getStringTag("id"); - if (idTag != null) { - // Handle new identifier - idTag.setValue(BlockEntityRewriter.toNewIdentifier(idTag.getValue())); - } - }); - } - }); - registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); @@ -223,11 +113,11 @@ public class Protocol1_10To1_11 extends AbstractProtocol newData = PotionColorMapping.getNewData(data); + Pair newData = PotionColors1_11.getNewData(data); if (newData == null) { Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")"); data = 0; @@ -357,7 +247,7 @@ public class Protocol1_10To1_11 extends AbstractProtocol. */ -package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter; +package com.viaversion.viaversion.protocols.v1_10to1_11.data; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.util.Key; -public class BlockEntityRewriter { +public class BlockEntityNames1_11 { private static final BiMap OLD_TO_NEW_NAMES = HashBiMap.create(); // Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityIdRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/EntityNames1_11.java similarity index 98% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityIdRewriter.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/EntityNames1_11.java index bd82d349b..9a13e07cb 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityIdRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/EntityNames1_11.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter; +package com.viaversion.viaversion.protocols.v1_10to1_11.data; import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.StringTag; @@ -24,7 +24,7 @@ import com.google.common.collect.HashBiMap; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.util.Key; -public class EntityIdRewriter { +public class EntityNames1_11 { private static final BiMap oldToNewNames = HashBiMap.create(); static { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColorMapping.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColors1_11.java similarity index 98% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColorMapping.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColors1_11.java index 91e6b37b8..90cce2df4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColorMapping.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/data/PotionColors1_11.java @@ -21,7 +21,7 @@ import com.viaversion.viaversion.util.Pair; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -public class PotionColorMapping { +public class PotionColors1_11 { // to mapping private static final Int2ObjectMap> POTIONS = new Int2ObjectOpenHashMap<>(37, 0.99F); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/metadata/MetadataRewriter1_11.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java similarity index 63% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/metadata/MetadataRewriter1_11.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java index df10dabfb..3a2964866 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/metadata/MetadataRewriter1_11.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java @@ -15,8 +15,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.v1_10to1_11.metadata; +package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11.EntityType; @@ -24,9 +26,12 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11; -import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.BlockEntityNames1_11; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11; import com.viaversion.viaversion.protocols.v1_10to1_11.storage.EntityTracker1_11; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; import com.viaversion.viaversion.rewriter.EntityRewriter; @@ -34,18 +39,130 @@ import java.util.List; import java.util.Optional; import java.util.logging.Level; -public class MetadataRewriter1_11 extends EntityRewriter { +public class EntityPacketRewriter1_11 extends EntityRewriter { - public MetadataRewriter1_11(Protocol1_10To1_11 protocol) { + public EntityPacketRewriter1_11(Protocol1_10To1_11 protocol) { super(protocol); } + @Override + protected void registerPackets() { + protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Entity id + map(Types.UUID); // 1 - UUID + map(Types.BYTE); // 2 - Type + + // Track Entity + handler(objectTrackerHandler()); + } + }); + + protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Entity ID + map(Types.UUID); // 1 - Entity UUID + map(Types.UNSIGNED_BYTE, Types.VAR_INT); // 2 - Entity Type + map(Types.DOUBLE); // 3 - X + map(Types.DOUBLE); // 4 - Y + map(Types.DOUBLE); // 5 - Z + map(Types.BYTE); // 6 - Yaw + map(Types.BYTE); // 7 - Pitch + map(Types.BYTE); // 8 - Head Pitch + map(Types.SHORT); // 9 - Velocity X + map(Types.SHORT); // 10 - Velocity Y + map(Types.SHORT); // 11 - Velocity Z + map(Types1_9.METADATA_LIST); // 12 - Metadata + + handler(wrapper -> { + int entityId = wrapper.get(Types.VAR_INT, 0); + // Change Type :) + int type = wrapper.get(Types.VAR_INT, 1); + + EntityTypes1_11.EntityType entType = EntityPacketRewriter1_11.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0)); + if (entType != null) { + wrapper.set(Types.VAR_INT, 1, entType.getId()); + + // Register Type ID + wrapper.user().getEntityTracker(Protocol1_10To1_11.class).addEntity(entityId, entType); + handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user()); + } + }); + } + }); + + protocol.registerClientbound(ClientboundPackets1_9_3.TAKE_ITEM_ENTITY, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Collected entity id + map(Types.VAR_INT); // 1 - Collector entity id + + handler(wrapper -> { + wrapper.write(Types.VAR_INT, 1); // 2 - Pickup Count + }); + } + }); + + registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_9.METADATA_LIST); + + protocol.registerClientbound(ClientboundPackets1_9_3.TELEPORT_ENTITY, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Entity id + map(Types.DOUBLE); // 1 - x + map(Types.DOUBLE); // 2 - y + map(Types.DOUBLE); // 3 - z + map(Types.BYTE); // 4 - yaw + map(Types.BYTE); // 5 - pitch + map(Types.BOOLEAN); // 6 - onGround + + handler(wrapper -> { + int entityID = wrapper.get(Types.VAR_INT, 0); + if (Via.getConfig().isHologramPatch()) { + EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_10To1_11.class); + if (tracker.isHologram(entityID)) { + Double newValue = wrapper.get(Types.DOUBLE, 1); + newValue -= (Via.getConfig().getHologramYOffset()); + wrapper.set(Types.DOUBLE, 1, newValue); + } + } + }); + } + }); + + registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES); + + protocol.registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketHandlers() { + @Override + public void register() { + map(Types.BLOCK_POSITION1_8); // 0 - Position + map(Types.UNSIGNED_BYTE); // 1 - Action + map(Types.NAMED_COMPOUND_TAG); // 2 - NBT data + + handler(wrapper -> { + CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0); + if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 1) { + EntityNames1_11.toClientSpawner(tag); + } + + StringTag idTag = tag.getStringTag("id"); + if (idTag != null) { + // Handle new identifier + idTag.setValue(BlockEntityNames1_11.toNewIdentifier(idTag.getValue())); + } + }); + } + }); + } + @Override protected void registerRewrites() { filter().handler((event, meta) -> { if (meta.getValue() instanceof DataItem) { // Apply rewrite - EntityIdRewriter.toClientItem(meta.value()); + EntityNames1_11.toClientItem(meta.value()); } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/ItemPacketRewriter1_11.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/ItemPacketRewriter1_11.java index 5e422ac79..8abfe8e60 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/ItemPacketRewriter1_11.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/ItemPacketRewriter1_11.java @@ -20,10 +20,9 @@ package com.viaversion.viaversion.protocols.v1_10to1_11.rewriter; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11; -import com.viaversion.viaversion.protocols.v1_10to1_11.rewriter.EntityIdRewriter; +import com.viaversion.viaversion.protocols.v1_10to1_11.data.EntityNames1_11; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3; import com.viaversion.viaversion.rewriter.ItemRewriter; @@ -52,12 +51,13 @@ public class ItemPacketRewriter1_11 extends ItemRewriter= 218 && item.identifier() <= 234; newItem |= item.identifier() == 449 || item.identifier() == 450; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/Protocol1_11_1To1_12.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/Protocol1_11_1To1_12.java index 356fed8da..bdf616cd7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/Protocol1_11_1To1_12.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/Protocol1_11_1To1_12.java @@ -33,18 +33,16 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_3; -import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.data.entity.EntityTrackerBase; -import com.viaversion.viaversion.protocols.v1_11_1to1_12.metadata.MetadataRewriter1_12To1_11_1; +import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.EntityPacketRewriter1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ClientboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPackets1_12; import com.viaversion.viaversion.protocols.v1_11_1to1_12.provider.InventoryQuickMoveProvider; -import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.ChatItemRewriter; +import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.ChatItemRewriter; import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.ItemPacketRewriter1_12; -import com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter.TranslateRewriter; +import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.TranslateRewriter; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; @@ -53,7 +51,7 @@ import com.viaversion.viaversion.rewriter.SoundRewriter; public class Protocol1_11_1To1_12 extends AbstractProtocol { - private final MetadataRewriter1_12To1_11_1 metadataRewriter = new MetadataRewriter1_12To1_11_1(this); + private final EntityPacketRewriter1_12 entityRewriter = new EntityPacketRewriter1_12(this); private final ItemPacketRewriter1_12 itemRewriter = new ItemPacketRewriter1_12(this); public Protocol1_11_1To1_12() { @@ -64,40 +62,6 @@ public class Protocol1_11_1To1_12 extends AbstractProtocol { if (!Via.getConfig().is1_12NBTArrayFix()) return; final JsonElement element = wrapper.passthrough(Types.COMPONENT); @@ -137,9 +101,6 @@ public class Protocol1_11_1To1_12 extends AbstractProtocol ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150, 0.99f); private static final Set SPECIAL_ACHIEVEMENTS = new HashSet<>(10); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/ChatItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/ChatItemRewriter.java similarity index 96% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/ChatItemRewriter.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/ChatItemRewriter.java index 022bf259d..d34039cd7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/ChatItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/ChatItemRewriter.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter; +package com.viaversion.viaversion.protocols.v1_11_1to1_12.data; import com.viaversion.nbt.tag.CompoundTag; import com.google.gson.JsonArray; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/TranslateRewriter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/TranslateRewriter.java similarity index 93% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/TranslateRewriter.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/TranslateRewriter.java index f25701cc3..e38a92697 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/TranslateRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/data/TranslateRewriter.java @@ -15,14 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter; +package com.viaversion.viaversion.protocols.v1_11_1to1_12.data; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.protocols.v1_11_1to1_12.data.AchievementTranslationMapping; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.util.SerializerVersion; @@ -33,7 +32,7 @@ public class TranslateRewriter { private static final ComponentRewriter ACHIEVEMENT_TEXT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) { @Override protected void handleTranslate(JsonObject object, String translate) { - String text = AchievementTranslationMapping.get(translate); + String text = AchievementTranslations1_12.get(translate); if (text != null) { object.addProperty("translate", text); } @@ -49,7 +48,7 @@ public class TranslateRewriter { String textValue = SerializerVersion.V1_9.toComponent(hoverEvent.get("value")).asUnformattedString(); - if (AchievementTranslationMapping.get(textValue) == null) { + if (AchievementTranslations1_12.get(textValue) == null) { JsonObject invalidText = new JsonObject(); invalidText.addProperty("text", "Invalid statistic/achievement!"); invalidText.addProperty("color", "red"); @@ -71,7 +70,7 @@ public class TranslateRewriter { baseArray.add(typePart); if (textValue.startsWith("achievement")) { namePart.addProperty("translate", textValue); - namePart.addProperty("color", AchievementTranslationMapping.isSpecial(textValue) ? "dark_purple" : "green"); + namePart.addProperty("color", AchievementTranslations1_12.isSpecial(textValue) ? "dark_purple" : "green"); typePart.addProperty("translate", "stats.tooltip.type.achievement"); JsonObject description = new JsonObject(); typePart.addProperty("italic", true); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/metadata/MetadataRewriter1_12To1_11_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/metadata/MetadataRewriter1_12To1_11_1.java deleted file mode 100644 index 693443863..000000000 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/metadata/MetadataRewriter1_12To1_11_1.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.protocols.v1_11_1to1_12.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; -import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.protocols.v1_11_1to1_12.Protocol1_11_1To1_12; -import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_12To1_11_1 extends EntityRewriter { - - public MetadataRewriter1_12To1_11_1(Protocol1_11_1To1_12 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - filter().handler((event, meta) -> { - if (meta.getValue() instanceof Item) { - meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())); - } - }); - - filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_12.getTypeFromId(type, false); - } - - @Override - public EntityType objectTypeFromId(int type) { - return EntityTypes1_12.getTypeFromId(type, true); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/EntityPacketRewriter1_12.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/EntityPacketRewriter1_12.java new file mode 100644 index 000000000..7db3d83d9 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_11_1to1_12/rewriter/EntityPacketRewriter1_12.java @@ -0,0 +1,96 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_11_1to1_12.rewriter; + +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_12; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_12; +import com.viaversion.viaversion.protocols.v1_11_1to1_12.Protocol1_11_1To1_12; +import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; +import com.viaversion.viaversion.rewriter.EntityRewriter; + +public class EntityPacketRewriter1_12 extends EntityRewriter { + + public EntityPacketRewriter1_12(Protocol1_11_1To1_12 protocol) { + super(protocol); + } + + @Override + protected void registerPackets() { + protocol.registerClientbound(ClientboundPackets1_9_3.ADD_ENTITY, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Entity id + map(Types.UUID); // 1 - UUID + map(Types.BYTE); // 2 - Type + + // Track Entity + handler(objectTrackerHandler()); + } + }); + + protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() { + @Override + public void register() { + map(Types.VAR_INT); // 0 - Entity ID + map(Types.UUID); // 1 - Entity UUID + map(Types.VAR_INT); // 2 - Entity Type + map(Types.DOUBLE); // 3 - X + map(Types.DOUBLE); // 4 - Y + map(Types.DOUBLE); // 5 - Z + map(Types.BYTE); // 6 - Yaw + map(Types.BYTE); // 7 - Pitch + map(Types.BYTE); // 8 - Head Pitch + map(Types.SHORT); // 9 - Velocity X + map(Types.SHORT); // 10 - Velocity Y + map(Types.SHORT); // 11 - Velocity Z + map(Types1_12.METADATA_LIST); // 12 - Metadata + + // Track mob and rewrite metadata + handler(trackerAndRewriterHandler(Types1_12.METADATA_LIST)); + } + }); + + registerRemoveEntities(ClientboundPackets1_9_3.REMOVE_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_9_3.SET_ENTITY_DATA, Types1_12.METADATA_LIST); + } + + @Override + protected void registerRewrites() { + filter().handler((event, meta) -> { + if (meta.getValue() instanceof Item) { + meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())); + } + }); + + filter().type(EntityTypes1_12.EntityType.EVOCATION_ILLAGER).index(12).toIndex(13); // Aggressive + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_12.getTypeFromId(type, false); + } + + @Override + public EntityType objectTypeFromId(int type) { + return EntityTypes1_12.getTypeFromId(type, true); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/Protocol1_12_2To1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/Protocol1_12_2To1_13.java index cb664fc5f..72b8685a1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/Protocol1_12_2To1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/Protocol1_12_2To1_13.java @@ -35,7 +35,6 @@ import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_13; @@ -56,11 +55,10 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.MappingData1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.RecipeData; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.StatisticData; import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.StatisticMappings; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.metadata.MetadataRewriter1_13To1_12_2; +import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.EntityPacketRewriter1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.BlockEntityProvider; import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PaintingProvider; import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.EntityPacketRewriter1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ItemPacketRewriter1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.WorldPacketRewriter1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.storage.BlockConnectionStorage; @@ -84,7 +82,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol SCOREBOARD_TEAM_NAME_REWRITE = new HashMap<>(); private static final Set FORMATTING_CODES = Sets.newHashSet('k', 'l', 'm', 'n', 'o', 'r'); - private final MetadataRewriter1_13To1_12_2 entityRewriter = new MetadataRewriter1_13To1_12_2(this); + private final EntityPacketRewriter1_13 entityRewriter = new EntityPacketRewriter1_13(this); private final ItemPacketRewriter1_13 itemRewriter = new ItemPacketRewriter1_13(this); private final ComponentRewriter1_13 componentRewriter = new ComponentRewriter1_13<>(this); @@ -172,7 +170,6 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol { @@ -904,7 +901,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_12_2to1_13.metadata; - -import com.viaversion.viaversion.api.minecraft.Particle; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; -import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.type.types.version.Types1_13; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.EntityTypeRewriter; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.ParticleRewriter; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.WorldPacketRewriter1_13; -import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1; -import com.viaversion.viaversion.rewriter.EntityRewriter; -import com.viaversion.viaversion.util.ComponentUtil; - -public class MetadataRewriter1_13To1_12_2 extends EntityRewriter { - - public MetadataRewriter1_13To1_12_2(Protocol1_12_2To1_13 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId)); - filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()))); - filter().metaType(Types1_13.META_TYPES.optionalBlockStateType).handler(((event, meta) -> { - final int oldId = meta.value(); - if (oldId != 0) { - final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); - final int newId = WorldPacketRewriter1_13.toNewId(combined); - meta.setValue(newId); - } - })); - - // Previously unused, now swimming - filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10))); - - filter().index(2).handler(((event, meta) -> { - if (meta.getValue() != null && !((String) meta.getValue()).isEmpty()) { - meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) meta.getValue())); - } else { - meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null); - } - })); - - filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> { - // Handle new colors - meta.setValue(15 - (int) meta.getValue()); - }); - - filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking - - filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> { - final int oldId = meta.value(); - final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); - final int newId = WorldPacketRewriter1_13.toNewId(combined); - meta.setValue(newId); - }); - - filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> { - if (meta.id() == 9) { - int particleId = meta.value(); - Metadata parameter1Meta = event.metaAtIndex(10); - Metadata parameter2Meta = event.metaAtIndex(11); - int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0; - int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0; - - Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2}); - if (particle != null && particle.id() != -1) { - event.createExtraMeta(new Metadata(9, Types1_13.META_TYPES.particleType, particle)); - } - } - if (meta.id() >= 9) { - event.cancel(); - } - }); - } - - @Override - public int newEntityId(final int id) { - return EntityTypeRewriter.getNewId(id); - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_13.getTypeFromId(type, false); - } - - @Override - public EntityType objectTypeFromId(int type) { - return EntityTypes1_13.getTypeFromId(type, true); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/EntityPacketRewriter1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/EntityPacketRewriter1_13.java index 64c35c8de..ba4c4544e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/EntityPacketRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/rewriter/EntityPacketRewriter1_13.java @@ -19,21 +19,29 @@ package com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.ClientWorld; +import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; +import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.metadata.MetadataRewriter1_13To1_12_2; +import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.EntityTypeRewriter; +import com.viaversion.viaversion.protocols.v1_12_2to1_13.data.ParticleRewriter; import com.viaversion.viaversion.protocols.v1_12to1_12_1.packet.ClientboundPackets1_12_1; +import com.viaversion.viaversion.rewriter.EntityRewriter; +import com.viaversion.viaversion.util.ComponentUtil; -public class EntityPacketRewriter1_13 { +public class EntityPacketRewriter1_13 extends EntityRewriter { - public static void register(Protocol1_12_2To1_13 protocol) { - MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class); + public EntityPacketRewriter1_13(Protocol1_12_2To1_13 protocol) { + super(protocol); + } + @Override + protected void registerPackets() { protocol.registerClientbound(ClientboundPackets1_12_1.ADD_ENTITY, new PacketHandlers() { @Override public void register() { @@ -96,7 +104,7 @@ public class EntityPacketRewriter1_13 { map(Types.SHORT); // 11 - Velocity Z map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST)); + handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST)); } }); @@ -112,7 +120,7 @@ public class EntityPacketRewriter1_13 { map(Types.BYTE); // 6 - Pitch map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); + handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); } }); @@ -128,7 +136,7 @@ public class EntityPacketRewriter1_13 { int dimensionId = wrapper.get(Types.INT, 1); clientChunks.setEnvironment(dimensionId); }); - handler(metadataRewriter.playerTrackerHandler()); + handler(playerTrackerHandler()); handler(Protocol1_12_2To1_13.SEND_DECLARE_COMMANDS_AND_TAGS); } }); @@ -152,7 +160,79 @@ public class EntityPacketRewriter1_13 { } }); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_12_1.REMOVE_ENTITIES); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_12_1.SET_ENTITY_DATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_12_1.REMOVE_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_12_1.SET_ENTITY_DATA, Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); } -} + + @Override + protected void registerRewrites() { + filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId)); + filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()))); + filter().metaType(Types1_13.META_TYPES.optionalBlockStateType).handler(((event, meta) -> { + final int oldId = meta.value(); + if (oldId != 0) { + final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); + final int newId = WorldPacketRewriter1_13.toNewId(combined); + meta.setValue(newId); + } + })); + + // Previously unused, now swimming + filter().index(0).handler((event, meta) -> meta.setValue((byte) ((byte) meta.getValue() & ~0x10))); + + filter().index(2).handler(((event, meta) -> { + if (meta.getValue() != null && !((String) meta.getValue()).isEmpty()) { + meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ComponentUtil.legacyToJson((String) meta.getValue())); + } else { + meta.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null); + } + })); + + filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, meta) -> { + // Handle new colors + meta.setValue(15 - (int) meta.getValue()); + }); + + filter().type(EntityTypes1_13.EntityType.ZOMBIE).addIndex(15); // Shaking + + filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> { + final int oldId = meta.value(); + final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); + final int newId = WorldPacketRewriter1_13.toNewId(combined); + meta.setValue(newId); + }); + + filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).handler((event, meta) -> { + if (meta.id() == 9) { + int particleId = meta.value(); + Metadata parameter1Meta = event.metaAtIndex(10); + Metadata parameter2Meta = event.metaAtIndex(11); + int parameter1 = parameter1Meta != null ? parameter1Meta.value() : 0; + int parameter2 = parameter2Meta != null ? parameter2Meta.value() : 0; + + Particle particle = ParticleRewriter.rewriteParticle(particleId, new Integer[]{parameter1, parameter2}); + if (particle != null && particle.id() != -1) { + event.createExtraMeta(new Metadata(9, Types1_13.META_TYPES.particleType, particle)); + } + } + if (meta.id() >= 9) { + event.cancel(); + } + }); + } + + @Override + public int newEntityId(final int id) { + return EntityTypeRewriter.getNewId(id); + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_13.getTypeFromId(type, false); + } + + @Override + public EntityType objectTypeFromId(int type) { + return EntityTypes1_13.getTypeFromId(type, true); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/Protocol1_13_2To1_14.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/Protocol1_13_2To1_14.java index 5b6ed2dcf..f7bff9639 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/Protocol1_13_2To1_14.java @@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; import com.viaversion.viaversion.api.protocol.AbstractProtocol; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_13_2; @@ -30,12 +29,11 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13_2to1_14.data.ComponentRewriter1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.data.MappingData1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.metadata.MetadataRewriter1_14To1_13_2; +import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.EntityPacketRewriter1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.EntityPacketRewriter1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.ItemPacketRewriter1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.PlayerPackets1_14; +import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.PlayerPacketRewriter1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.WorldPacketRewriter1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14; import com.viaversion.viaversion.rewriter.CommandRewriter; @@ -47,7 +45,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class Protocol1_13_2To1_14 extends AbstractProtocol { public static final MappingData1_14 MAPPINGS = new MappingData1_14(); - private final MetadataRewriter1_14To1_13_2 metadataRewriter = new MetadataRewriter1_14To1_13_2(this); + private final EntityPacketRewriter1_14 entityRewriter = new EntityPacketRewriter1_14(this); private final ItemPacketRewriter1_14 itemRewriter = new ItemPacketRewriter1_14(this); public Protocol1_13_2To1_14() { @@ -58,9 +56,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol(this).registerSound(ClientboundPackets1_13.SOUND); new StatisticsRewriter<>(this).register(ClientboundPackets1_13.AWARD_STATS); @@ -177,8 +174,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_13_2to1_14.metadata; - -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.minecraft.VillagerData; -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; -import com.viaversion.viaversion.api.minecraft.item.DataItem; -import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.Types; -import com.viaversion.viaversion.api.type.types.version.Types1_14; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_14To1_13_2 extends EntityRewriter { - - public MetadataRewriter1_14To1_13_2(Protocol1_13_2To1_14 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - filter().mapMetaType(Types1_14.META_TYPES::byId); - registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType); - - filter().type(EntityTypes1_14.ENTITY).addIndex(6); - filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12); - - filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> { - float value = ((Number) meta.getValue()).floatValue(); - if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) { - meta.setValue(1F); - } - }); - - filter().type(EntityTypes1_14.MOB).index(13).handler((event, meta) -> { - EntityTracker1_14 tracker = tracker(event.user()); - int entityId = event.entityId(); - tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4) - | (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata - meta.setValue(tracker.getInsentientData(entityId)); - }); - - filter().type(EntityTypes1_14.PLAYER).handler((event, meta) -> { - EntityTracker1_14 tracker = tracker(event.user()); - int entityId = event.entityId(); - if (entityId != tracker.clientEntityId()) { - if (meta.id() == 0) { - byte flags = ((Number) meta.getValue()).byteValue(); - // Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize - tracker.setEntityFlags(entityId, flags); - } else if (meta.id() == 7) { - tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0); - } - if (meta.id() == 0 || meta.id() == 7) { - event.createExtraMeta(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker))); - } - } - }); - - filter().type(EntityTypes1_14.ZOMBIE).handler((event, meta) -> { - if (meta.id() == 16) { - EntityTracker1_14 tracker = tracker(event.user()); - int entityId = event.entityId(); - tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) - | ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking - event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); - event.cancel(); // "Are hands held up" - } else if (meta.id() > 16) { - meta.setId(meta.id() - 1); - } - }); - - filter().type(EntityTypes1_14.ABSTRACT_MINECART).index(10).handler((event, meta) -> { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - - filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> { - event.cancel(); - - int armorType = meta.value(); - Item armorItem = null; - if (armorType == 1) { //iron armor - armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null); - } else if (armorType == 2) { //gold armor - armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null); - } else if (armorType == 3) { //diamond armor - armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null); - } - - PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.SET_EQUIPPED_ITEM, null, event.user()); - equipmentPacket.write(Types.VAR_INT, event.entityId()); - equipmentPacket.write(Types.VAR_INT, 4); - equipmentPacket.write(Types.ITEM1_13_2, armorItem); - try { - equipmentPacket.scheduleSend(Protocol1_13_2To1_14.class); - } catch (final Exception e) { - throw new RuntimeException(e); - } - }); - - filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> { - meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0)); - }); - - filter().type(EntityTypes1_14.ZOMBIE_VILLAGER).index(18).handler((event, meta) -> { - meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0)); - }); - - filter().type(EntityTypes1_14.ABSTRACT_ARROW).addIndex(9); // Piercing level added - - filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> { - meta.setMetaType(Types1_14.META_TYPES.optionalVarIntType); - if (meta.getValue().equals(0)) { - meta.setValue(null); // https://bugs.mojang.com/browse/MC-111480 - } - }); - - filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(14).handler((event, meta) -> { - EntityTracker1_14 tracker = tracker(event.user()); - int entityId = event.entityId(); - tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) - | ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking - event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); - event.cancel(); // "Is swinging arms" - }); - - filter().type(EntityTypes1_14.ABSTRACT_ILLAGER).handler((event, meta) -> { - if (event.index() == 14) { - EntityTracker1_14 tracker = tracker(event.user()); - int entityId = event.entityId(); - tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) - | (((Number) meta.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking - event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); - event.cancel(); // "Has target (aggressive state)" - } else if (event.index() > 14) { - meta.setId(meta.id() - 1); - } - }); - - filter().type(EntityTypes1_14.OCELOT).removeIndex(17); // variant - - // Ocelot is not tamable anymore - filter().type(EntityTypes1_14.OCELOT).removeIndex(16); // owner uuid - filter().type(EntityTypes1_14.OCELOT).removeIndex(15); // data - - filter().type(EntityTypes1_14.ABSTRACT_RAIDER).addIndex(14); // celebrating - } - - @Override - public void onMappingDataLoaded() { - mapTypes(); - if (Via.getConfig().translateOcelotToCat()) { - // A better solution for this would be to despawn the ocelot and spawn a cat in its place, but that would - // require a lot of data tracking and is not worth the effort. - mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT); - } - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_14.getTypeFromId(type); - } - - private static boolean isSneaking(byte flags) { - return (flags & 0x2) != 0; - } - - private static boolean isSwimming(byte flags) { - return (flags & 0x10) != 0; - } - - private static int getNewProfessionId(int old) { - // profession -> career - return switch (old) { - case 0 -> 5; // farmer - case 1 -> 9; // librarian - case 2 -> 4; // priest ->cleric - case 3 -> 1; // blacksmith -> armorer - case 4 -> 2; // butcher - case 5 -> 11; // nitwit - default -> 0; // none - }; - } - - private static boolean isFallFlying(int entityFlags) { - return (entityFlags & 0x80) != 0; - } - - public static int recalculatePlayerPose(int entityId, EntityTracker1_14 tracker) { - byte flags = tracker.getEntityFlags(entityId); - // Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize - int pose = 0; // standing - if (isFallFlying(flags)) { - pose = 1; - } else if (tracker.isSleeping(entityId)) { - pose = 2; - } else if (isSwimming(flags)) { - pose = 3; - } else if (tracker.isRiptide(entityId)) { - pose = 4; - } else if (isSneaking(flags)) { - pose = 5; - } - return pose; - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java index ea695b3d2..bcdac33e3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java @@ -17,40 +17,46 @@ */ package com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter; +import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Position; +import com.viaversion.viaversion.api.minecraft.VillagerData; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; +import com.viaversion.viaversion.api.minecraft.item.DataItem; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_13_2; import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.metadata.MetadataRewriter1_14To1_13_2; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14; +import com.viaversion.viaversion.rewriter.EntityRewriter; import java.util.LinkedList; import java.util.List; -public class EntityPacketRewriter1_14 { +public class EntityPacketRewriter1_14 extends EntityRewriter { - public static void register(Protocol1_13_2To1_14 protocol) { - MetadataRewriter1_14To1_13_2 metadataRewriter = protocol.get(MetadataRewriter1_14To1_13_2.class); + public EntityPacketRewriter1_14(Protocol1_13_2To1_14 protocol) { + super(protocol); + } + @Override + protected void registerPackets() { protocol.registerClientbound(ClientboundPackets1_13.ADD_EXPERIENCE_ORB, wrapper -> { int entityId = wrapper.passthrough(Types.VAR_INT); - metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.EXPERIENCE_ORB); + tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.EXPERIENCE_ORB); }); protocol.registerClientbound(ClientboundPackets1_13.ADD_GLOBAL_ENTITY, wrapper -> { int entityId = wrapper.passthrough(Types.VAR_INT); if (wrapper.passthrough(Types.BYTE) == 1) { - metadataRewriter.tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.LIGHTNING_BOLT); + tracker(wrapper.user()).addEntity(entityId, EntityTypes1_14.LIGHTNING_BOLT); } }); @@ -76,7 +82,7 @@ public class EntityPacketRewriter1_14 { int typeId = wrapper.get(Types.VAR_INT, 1); EntityTypes1_13.EntityType type1_13 = EntityTypes1_13.getTypeFromId(typeId, true); - typeId = metadataRewriter.newEntityId(type1_13.getId()); + typeId = newEntityId(type1_13.getId()); EntityType type1_14 = EntityTypes1_14.getTypeFromId(typeId); if (type1_14 != null) { @@ -94,7 +100,7 @@ public class EntityPacketRewriter1_14 { default -> typeId; // default 0 = rideable minecart }; } else if ((type1_14.is(EntityTypes1_14.ITEM) && data > 0) - || type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { + || type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { if (type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { wrapper.set(Types.INT, 0, data - 1); } @@ -133,7 +139,7 @@ public class EntityPacketRewriter1_14 { map(Types.SHORT); // 11 - Velocity Z map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST)); + handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST)); } }); @@ -145,7 +151,7 @@ public class EntityPacketRewriter1_14 { map(Types.VAR_INT); map(Types.BLOCK_POSITION1_8, Types.BLOCK_POSITION1_14); map(Types.BYTE); - handler(wrapper -> metadataRewriter.tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), EntityTypes1_14.PAINTING)); + handler(wrapper -> tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), EntityTypes1_14.PAINTING)); } }); @@ -161,7 +167,7 @@ public class EntityPacketRewriter1_14 { map(Types.BYTE); // 6 - Pitch map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER)); + handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER)); } }); @@ -180,7 +186,7 @@ public class EntityPacketRewriter1_14 { metadataPacket.write(Types.VAR_INT, entityId); List metadataList = new LinkedList<>(); if (tracker.clientEntityId() != entityId) { - metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); + metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, EntityPacketRewriter1_14.recalculatePlayerPose(entityId, tracker))); } metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalBlockPositionType, null)); metadataPacket.write(Types1_14.METADATA_LIST, metadataList); @@ -202,7 +208,7 @@ public class EntityPacketRewriter1_14 { int dimensionId = wrapper.get(Types.INT, 1); clientChunks.setEnvironment(dimensionId); }); - handler(metadataRewriter.playerTrackerHandler()); + handler(playerTrackerHandler()); handler(wrapper -> { short difficulty = wrapper.read(Types.UNSIGNED_BYTE); // 19w11a removed difficulty from join game PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.CHANGE_DIFFICULTY); @@ -239,14 +245,202 @@ public class EntityPacketRewriter1_14 { List metadataList = new LinkedList<>(); metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalBlockPositionType, position)); if (tracker.clientEntityId() != entityId) { - metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); + metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, EntityPacketRewriter1_14.recalculatePlayerPose(entityId, tracker))); } wrapper.write(Types1_14.METADATA_LIST, metadataList); }); } }); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); + } + + @Override + protected void registerRewrites() { + filter().mapMetaType(Types1_14.META_TYPES::byId); + registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType); + + filter().type(EntityTypes1_14.ENTITY).addIndex(6); + filter().type(EntityTypes1_14.LIVING_ENTITY).addIndex(12); + + filter().type(EntityTypes1_14.LIVING_ENTITY).index(8).handler((event, meta) -> { + float value = ((Number) meta.getValue()).floatValue(); + if (Float.isNaN(value) && Via.getConfig().is1_14HealthNaNFix()) { + meta.setValue(1F); + } + }); + + filter().type(EntityTypes1_14.MOB).index(13).handler((event, meta) -> { + EntityTracker1_14 tracker = tracker(event.user()); + int entityId = event.entityId(); + tracker.setInsentientData(entityId, (byte) ((((Number) meta.getValue()).byteValue() & ~0x4) + | (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata + meta.setValue(tracker.getInsentientData(entityId)); + }); + + filter().type(EntityTypes1_14.PLAYER).handler((event, meta) -> { + EntityTracker1_14 tracker = tracker(event.user()); + int entityId = event.entityId(); + if (entityId != tracker.clientEntityId()) { + if (meta.id() == 0) { + byte flags = ((Number) meta.getValue()).byteValue(); + // Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize + tracker.setEntityFlags(entityId, flags); + } else if (meta.id() == 7) { + tracker.setRiptide(entityId, (((Number) meta.getValue()).byteValue() & 0x4) != 0); + } + if (meta.id() == 0 || meta.id() == 7) { + event.createExtraMeta(new Metadata(6, Types1_14.META_TYPES.poseType, recalculatePlayerPose(entityId, tracker))); + } + } + }); + + filter().type(EntityTypes1_14.ZOMBIE).handler((event, meta) -> { + if (meta.id() == 16) { + EntityTracker1_14 tracker = tracker(event.user()); + int entityId = event.entityId(); + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking + event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); + event.cancel(); // "Are hands held up" + } else if (meta.id() > 16) { + meta.setId(meta.id() - 1); + } + }); + + filter().type(EntityTypes1_14.ABSTRACT_MINECART).index(10).handler((event, meta) -> { + int data = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + + filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> { + event.cancel(); + + int armorType = meta.value(); + Item armorItem = null; + if (armorType == 1) { //iron armor + armorItem = new DataItem(protocol.getMappingData().getNewItemId(727), (byte) 1, (short) 0, null); + } else if (armorType == 2) { //gold armor + armorItem = new DataItem(protocol.getMappingData().getNewItemId(728), (byte) 1, (short) 0, null); + } else if (armorType == 3) { //diamond armor + armorItem = new DataItem(protocol.getMappingData().getNewItemId(729), (byte) 1, (short) 0, null); + } + + PacketWrapper equipmentPacket = PacketWrapper.create(ClientboundPackets1_14.SET_EQUIPPED_ITEM, null, event.user()); + equipmentPacket.write(Types.VAR_INT, event.entityId()); + equipmentPacket.write(Types.VAR_INT, 4); + equipmentPacket.write(Types.ITEM1_13_2, armorItem); + try { + equipmentPacket.scheduleSend(Protocol1_13_2To1_14.class); + } catch (final Exception e) { + throw new RuntimeException(e); + } + }); + + filter().type(EntityTypes1_14.VILLAGER).index(15).handler((event, meta) -> { + meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0)); + }); + + filter().type(EntityTypes1_14.ZOMBIE_VILLAGER).index(18).handler((event, meta) -> { + meta.setTypeAndValue(Types1_14.META_TYPES.villagerDatatType, new VillagerData(2, getNewProfessionId(meta.value()), 0)); + }); + + filter().type(EntityTypes1_14.ABSTRACT_ARROW).addIndex(9); // Piercing level added + + filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> { + meta.setMetaType(Types1_14.META_TYPES.optionalVarIntType); + if (meta.getValue().equals(0)) { + meta.setValue(null); // https://bugs.mojang.com/browse/MC-111480 + } + }); + + filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(14).handler((event, meta) -> { + EntityTracker1_14 tracker = tracker(event.user()); + int entityId = event.entityId(); + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) meta.getValue() ? 0x4 : 0))); // New attacking + event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); + event.cancel(); // "Is swinging arms" + }); + + filter().type(EntityTypes1_14.ABSTRACT_ILLAGER).handler((event, meta) -> { + if (event.index() == 14) { + EntityTracker1_14 tracker = tracker(event.user()); + int entityId = event.entityId(); + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | (((Number) meta.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking + event.createExtraMeta(new Metadata(13, Types1_14.META_TYPES.byteType, tracker.getInsentientData(entityId))); + event.cancel(); // "Has target (aggressive state)" + } else if (event.index() > 14) { + meta.setId(meta.id() - 1); + } + }); + + filter().type(EntityTypes1_14.OCELOT).removeIndex(17); // variant + + // Ocelot is not tamable anymore + filter().type(EntityTypes1_14.OCELOT).removeIndex(16); // owner uuid + filter().type(EntityTypes1_14.OCELOT).removeIndex(15); // data + + filter().type(EntityTypes1_14.ABSTRACT_RAIDER).addIndex(14); // celebrating + } + + @Override + public void onMappingDataLoaded() { + mapTypes(); + if (Via.getConfig().translateOcelotToCat()) { + // A better solution for this would be to despawn the ocelot and spawn a cat in its place, but that would + // require a lot of data tracking and is not worth the effort. + mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT); + } + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_14.getTypeFromId(type); + } + + private static boolean isSneaking(byte flags) { + return (flags & 0x2) != 0; + } + + private static boolean isSwimming(byte flags) { + return (flags & 0x10) != 0; + } + + private static int getNewProfessionId(int old) { + // profession -> career + return switch (old) { + case 0 -> 5; // farmer + case 1 -> 9; // librarian + case 2 -> 4; // priest ->cleric + case 3 -> 1; // blacksmith -> armorer + case 4 -> 2; // butcher + case 5 -> 11; // nitwit + default -> 0; // none + }; + } + + private static boolean isFallFlying(int entityFlags) { + return (entityFlags & 0x80) != 0; + } + + public static int recalculatePlayerPose(int entityId, EntityTracker1_14 tracker) { + byte flags = tracker.getEntityFlags(entityId); + // Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize + int pose = 0; // standing + if (isFallFlying(flags)) { + pose = 1; + } else if (tracker.isSleeping(entityId)) { + pose = 2; + } else if (isSwimming(flags)) { + pose = 3; + } else if (tracker.isRiptide(entityId)) { + pose = 4; + } else if (isSneaking(flags)) { + pose = 5; + } + return pose; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPackets1_14.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPacketRewriter1_14.java similarity index 98% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPackets1_14.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPacketRewriter1_14.java index eb4b853a4..1a7f3f164 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPackets1_14.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/PlayerPacketRewriter1_14.java @@ -24,14 +24,12 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; -import java.util.Collections; -public class PlayerPackets1_14 { +public class PlayerPacketRewriter1_14 { public static void register(Protocol1_13_2To1_14 protocol) { protocol.registerClientbound(ClientboundPackets1_13.OPEN_SIGN_EDITOR, new PacketHandlers() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/Protocol1_13To1_13_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/Protocol1_13To1_13_1.java index 94d6ee10a..d4710ef76 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/Protocol1_13To1_13_1.java @@ -28,12 +28,10 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13; -import com.viaversion.viaversion.protocols.v1_13to1_13_1.metadata.MetadataRewriter1_13_1To1_13; import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.EntityPacketRewriter1_13_1; import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.ItemPacketRewriter1_13_1; import com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter.WorldPacketRewriter1_13_1; @@ -43,7 +41,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter; public class Protocol1_13To1_13_1 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.13", "1.13.2"); - private final MetadataRewriter1_13_1To1_13 entityRewriter = new MetadataRewriter1_13_1To1_13(this); + private final EntityPacketRewriter1_13_1 entityRewriter = new EntityPacketRewriter1_13_1(this); private final ItemPacketRewriter1_13_1 itemRewriter = new ItemPacketRewriter1_13_1(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -55,7 +53,6 @@ public class Protocol1_13To1_13_1 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_13to1_13_1.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; -import com.viaversion.viaversion.api.type.types.version.Types1_13; -import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; -import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_13_1To1_13 extends EntityRewriter { - - public MetadataRewriter1_13_1To1_13(Protocol1_13To1_13_1 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.optionalBlockStateType, Types1_13.META_TYPES.particleType); - filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_13.getTypeFromId(type, false); - } - - @Override - public EntityType objectTypeFromId(int type) { - return EntityTypes1_13.getTypeFromId(type, true); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java index e1d78057e..eb4d7d0ae 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java @@ -17,20 +17,23 @@ */ package com.viaversion.viaversion.protocols.v1_13to1_13_1.rewriter; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.v1_13to1_13_1.Protocol1_13To1_13_1; -import com.viaversion.viaversion.protocols.v1_13to1_13_1.metadata.MetadataRewriter1_13_1To1_13; +import com.viaversion.viaversion.rewriter.EntityRewriter; -public class EntityPacketRewriter1_13_1 { +public class EntityPacketRewriter1_13_1 extends EntityRewriter { - public static void register(Protocol1_13To1_13_1 protocol) { - MetadataRewriter1_13_1To1_13 metadataRewriter = protocol.get(MetadataRewriter1_13_1To1_13.class); + public EntityPacketRewriter1_13_1(Protocol1_13To1_13_1 protocol) { + super(protocol); + } + @Override + protected void registerPackets() { protocol.registerClientbound(ClientboundPackets1_13.ADD_ENTITY, new PacketHandlers() { @Override public void register() { @@ -79,7 +82,7 @@ public class EntityPacketRewriter1_13_1 { map(Types.SHORT); // 11 - Velocity Z map(Types1_13.METADATA_LIST); // 12 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST)); + handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST)); } }); @@ -95,11 +98,31 @@ public class EntityPacketRewriter1_13_1 { map(Types.BYTE); // 6 - Pitch map(Types1_13.METADATA_LIST); // 7 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); + handler(trackerAndRewriterHandler(Types1_13.METADATA_LIST, EntityTypes1_13.EntityType.PLAYER)); } }); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_13.REMOVE_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_13.SET_ENTITY_DATA, Types1_13.METADATA_LIST); + } + + @Override + protected void registerRewrites() { + registerMetaTypeHandler(Types1_13.META_TYPES.itemType, Types1_13.META_TYPES.optionalBlockStateType, Types1_13.META_TYPES.particleType); + filter().type(EntityTypes1_13.EntityType.MINECART_ABSTRACT).index(9).handler((event, meta) -> { + int data = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_13.getTypeFromId(type, false); + } + + @Override + public EntityType objectTypeFromId(int type) { + return EntityTypes1_13.getTypeFromId(type, true); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/Protocol1_14_4To1_15.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/Protocol1_14_4To1_15.java index 8afe6d95a..c3b75590f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/Protocol1_14_4To1_15.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/Protocol1_14_4To1_15.java @@ -23,14 +23,12 @@ import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15; import com.viaversion.viaversion.api.protocol.AbstractProtocol; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.metadata.MetadataRewriter1_15To1_14_4; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.EntityPacketRewriter1_15; +import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.ItemPacketRewriter1_15; import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.WorldPacketRewriter1_15; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -40,7 +38,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter; public class Protocol1_14_4To1_15 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.14", "1.15"); - private final MetadataRewriter1_15To1_14_4 metadataRewriter = new MetadataRewriter1_15To1_14_4(this); + private final EntityPacketRewriter1_15 entityRewriter = new EntityPacketRewriter1_15(this); private final ItemPacketRewriter1_15 itemRewriter = new ItemPacketRewriter1_15(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -52,7 +50,6 @@ public class Protocol1_14_4To1_15 extends AbstractProtocol soundRewriter = new SoundRewriter<>(this); @@ -91,8 +88,8 @@ public class Protocol1_14_4To1_15 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_14_4to1_15.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15; -import com.viaversion.viaversion.api.type.types.version.Types1_14; -import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.EntityPacketRewriter1_15; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_15To1_14_4 extends EntityRewriter { - - public MetadataRewriter1_15To1_14_4(Protocol1_14_4To1_15 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType); - filter().type(EntityTypes1_15.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - - filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12); - filter().type(EntityTypes1_15.WOLF).removeIndex(18); - } - - @Override - public int newEntityId(final int id) { - return EntityPacketRewriter1_15.getNewEntityId(id); - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_15.getTypeFromId(type); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java index 2c791d5cf..32cdfdf62 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java @@ -18,26 +18,28 @@ package com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.protocols.v1_14_3to1_14_4.packet.ClientboundPackets1_14_4; import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.metadata.MetadataRewriter1_15To1_14_4; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.rewriter.EntityRewriter; import java.util.List; -public final class EntityPacketRewriter1_15 { +public class EntityPacketRewriter1_15 extends EntityRewriter { - public static void register(Protocol1_14_4To1_15 protocol) { - MetadataRewriter1_15To1_14_4 metadataRewriter = protocol.get(MetadataRewriter1_15To1_14_4.class); + public EntityPacketRewriter1_15(Protocol1_14_4To1_15 protocol) { + super(protocol); + } - metadataRewriter.registerTrackerWithData(ClientboundPackets1_14_4.ADD_ENTITY, EntityTypes1_15.FALLING_BLOCK); + @Override + protected void registerPackets() { + registerTrackerWithData(ClientboundPackets1_14_4.ADD_ENTITY, EntityTypes1_15.FALLING_BLOCK); protocol.registerClientbound(ClientboundPackets1_14_4.ADD_MOB, new PacketHandlers() { @Override @@ -55,8 +57,8 @@ public final class EntityPacketRewriter1_15 { map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 11 - Velocity Z - handler(metadataRewriter.trackerHandler()); - handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Types.VAR_INT, 0), metadataRewriter)); + handler(trackerHandler()); + handler(wrapper -> sendMetadataPacket(wrapper, wrapper.get(Types.VAR_INT, 0))); } }); @@ -75,7 +77,7 @@ public final class EntityPacketRewriter1_15 { int entityId = wrapper.get(Types.VAR_INT, 0); wrapper.user().getEntityTracker(Protocol1_14_4To1_15.class).addEntity(entityId, EntityTypes1_15.PLAYER); - sendMetadataPacket(wrapper, entityId, metadataRewriter); + sendMetadataPacket(wrapper, entityId); }); } }); @@ -94,7 +96,7 @@ public final class EntityPacketRewriter1_15 { map(Types.INT); // 0 - Entity ID map(Types.UNSIGNED_BYTE); // 1 - Gamemode map(Types.INT); // 2 - Dimension - handler(metadataRewriter.playerTrackerHandler()); + handler(playerTrackerHandler()); handler(wrapper -> wrapper.write(Types.LONG, 0L)); // Level Seed map(Types.UNSIGNED_BYTE); // 3 - Max Players @@ -106,11 +108,24 @@ public final class EntityPacketRewriter1_15 { } }); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14_4.SET_ENTITY_DATA, Types1_14.METADATA_LIST); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_14_4.REMOVE_ENTITIES); + registerMetadataRewriter(ClientboundPackets1_14_4.SET_ENTITY_DATA, Types1_14.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_14_4.REMOVE_ENTITIES); } - private static void sendMetadataPacket(PacketWrapper wrapper, int entityId, EntityRewriter rewriter) { + @Override + protected void registerRewrites() { + registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.optionalBlockStateType, Types1_14.META_TYPES.particleType); + filter().type(EntityTypes1_15.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { + int data = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + + filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12); + filter().type(EntityTypes1_15.WOLF).removeIndex(18); + } + + + private void sendMetadataPacket(PacketWrapper wrapper, int entityId) { // Meta is no longer included in the spawn packets, but sent separately List metadata = wrapper.read(Types1_14.METADATA_LIST); if (metadata.isEmpty()) { @@ -122,7 +137,7 @@ public final class EntityPacketRewriter1_15 { wrapper.cancel(); // Handle meta - rewriter.handleMetadata(entityId, metadata, wrapper.user()); + handleMetadata(entityId, metadata, wrapper.user()); PacketWrapper metadataPacket = PacketWrapper.create(ClientboundPackets1_15.SET_ENTITY_DATA, wrapper.user()); metadataPacket.write(Types.VAR_INT, entityId); @@ -130,7 +145,13 @@ public final class EntityPacketRewriter1_15 { metadataPacket.send(Protocol1_14_4To1_15.class); } - public static int getNewEntityId(int oldId) { - return oldId >= 4 ? oldId + 1 : oldId; // 4 = bee + @Override + public int newEntityId(final int id) { + return id >= 4 ? id + 1 : id; // 4 = bee + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_15.getTypeFromId(type); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/Protocol1_14To1_14_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/Protocol1_14To1_14_1.java index 13849a160..55363d7d2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/Protocol1_14To1_14_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/Protocol1_14To1_14_1.java @@ -23,12 +23,11 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; -import com.viaversion.viaversion.protocols.v1_14to1_14_1.metadata.MetadataRewriter1_14_1To1_14; import com.viaversion.viaversion.protocols.v1_14to1_14_1.rewriter.EntityPacketRewriter1_14_1; public class Protocol1_14To1_14_1 extends AbstractProtocol { - private final MetadataRewriter1_14_1To1_14 metadataRewriter = new MetadataRewriter1_14_1To1_14(this); + private final EntityPacketRewriter1_14_1 entityRewriter = new EntityPacketRewriter1_14_1(this); public Protocol1_14To1_14_1() { super(ClientboundPackets1_14.class, ClientboundPackets1_14.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class); @@ -36,9 +35,7 @@ public class Protocol1_14To1_14_1 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_14to1_14_1.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; -import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; -import com.viaversion.viaversion.protocols.v1_14to1_14_1.Protocol1_14To1_14_1; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_14_1To1_14 extends EntityRewriter { - - public MetadataRewriter1_14_1To1_14(Protocol1_14To1_14_1 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - filter().type(EntityTypes1_14.VILLAGER).addIndex(15); - filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15); - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_14.getTypeFromId(type); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/rewriter/EntityPacketRewriter1_14_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/rewriter/EntityPacketRewriter1_14_1.java index 10a55134c..c71b97775 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/rewriter/EntityPacketRewriter1_14_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14to1_14_1/rewriter/EntityPacketRewriter1_14_1.java @@ -17,20 +17,23 @@ */ package com.viaversion.viaversion.protocols.v1_14to1_14_1.rewriter; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.v1_14to1_14_1.Protocol1_14To1_14_1; -import com.viaversion.viaversion.protocols.v1_14to1_14_1.metadata.MetadataRewriter1_14_1To1_14; +import com.viaversion.viaversion.rewriter.EntityRewriter; -public class EntityPacketRewriter1_14_1 { +public class EntityPacketRewriter1_14_1 extends EntityRewriter { - public static void register(Protocol1_14To1_14_1 protocol) { - MetadataRewriter1_14_1To1_14 metadataRewriter = protocol.get(MetadataRewriter1_14_1To1_14.class); + public EntityPacketRewriter1_14_1(Protocol1_14To1_14_1 protocol) { + super(protocol); + } + @Override + protected void registerPackets() { protocol.registerClientbound(ClientboundPackets1_14.ADD_MOB, new PacketHandlers() { @Override public void register() { @@ -48,11 +51,11 @@ public class EntityPacketRewriter1_14_1 { map(Types.SHORT); // 11 - Velocity Z map(Types1_14.METADATA_LIST); // 12 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST)); + handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST)); } }); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_14.REMOVE_ENTITIES); + registerRemoveEntities(ClientboundPackets1_14.REMOVE_ENTITIES); protocol.registerClientbound(ClientboundPackets1_14.ADD_PLAYER, new PacketHandlers() { @Override @@ -66,10 +69,21 @@ public class EntityPacketRewriter1_14_1 { map(Types.BYTE); // 6 - Pitch map(Types1_14.METADATA_LIST); // 7 - Metadata - handler(metadataRewriter.trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER)); + handler(trackerAndRewriterHandler(Types1_14.METADATA_LIST, EntityTypes1_14.PLAYER)); } }); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.METADATA_LIST); + registerMetadataRewriter(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.METADATA_LIST); + } + + @Override + protected void registerRewrites() { + filter().type(EntityTypes1_14.VILLAGER).addIndex(15); + filter().type(EntityTypes1_14.WANDERING_TRADER).addIndex(15); + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_14.getTypeFromId(type); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/Protocol1_15_2To1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/Protocol1_15_2To1_16.java index c0ff9f3e1..7da64e8fe 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/Protocol1_15_2To1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/Protocol1_15_2To1_16.java @@ -31,7 +31,6 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_16; @@ -40,12 +39,11 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets; import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.TranslationMappings; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.metadata.MetadataRewriter1_16To1_15_2; +import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ComponentRewriter1_16; +import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.EntityPacketRewriter1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.EntityPacketRewriter1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ItemPacketRewriter1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.WorldPacketRewriter1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16; @@ -63,9 +61,9 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); public Protocol1_15_2To1_16() { @@ -76,7 +74,6 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol ATTRIBUTE_MAPPINGS = HashBiMap.create(); static { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/DimensionRegistries1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/DimensionRegistries1_16.java new file mode 100644 index 000000000..16b10a9f2 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/DimensionRegistries1_16.java @@ -0,0 +1,119 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_15_2to1_16.data; + +import com.viaversion.nbt.tag.ByteTag; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.FloatTag; +import com.viaversion.nbt.tag.IntTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.nbt.tag.LongTag; +import com.viaversion.nbt.tag.StringTag; +import java.util.Arrays; + +public class DimensionRegistries1_16 { + + private static final CompoundTag DIMENSIONS_TAG = new CompoundTag(); + private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"}; + + static { + ListTag list = new ListTag<>(CompoundTag.class); + list.add(createOverworldEntry()); + list.add(createOverworldCavesEntry()); + list.add(createNetherEntry()); + list.add(createEndEntry()); + DIMENSIONS_TAG.put("dimension", list); + } + + public static CompoundTag getDimensionsTag() { + return DIMENSIONS_TAG.copy(); + } + + public static String[] getWorldNames() { + return Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length); + } + + private static CompoundTag createOverworldEntry() { + CompoundTag tag = new CompoundTag(); + tag.put("name", new StringTag("minecraft:overworld")); + tag.put("has_ceiling", new ByteTag((byte) 0)); + addSharedOverwaldEntries(tag); + return tag; + } + + private static CompoundTag createOverworldCavesEntry() { + CompoundTag tag = new CompoundTag(); + tag.put("name", new StringTag("minecraft:overworld_caves")); + tag.put("has_ceiling", new ByteTag((byte) 1)); + addSharedOverwaldEntries(tag); + return tag; + } + + private static void addSharedOverwaldEntries(CompoundTag tag) { + tag.put("piglin_safe", new ByteTag((byte) 0)); + tag.put("natural", new ByteTag((byte) 1)); + tag.put("ambient_light", new FloatTag(0)); + tag.put("infiniburn", new StringTag("minecraft:infiniburn_overworld")); + tag.put("respawn_anchor_works", new ByteTag((byte) 0)); + tag.put("has_skylight", new ByteTag((byte) 1)); + tag.put("bed_works", new ByteTag((byte) 1)); + tag.put("has_raids", new ByteTag((byte) 1)); + tag.put("logical_height", new IntTag(256)); + tag.put("shrunk", new ByteTag((byte) 0)); + tag.put("ultrawarm", new ByteTag((byte) 0)); + } + + private static CompoundTag createNetherEntry() { + CompoundTag tag = new CompoundTag(); + tag.put("piglin_safe", new ByteTag((byte) 1)); + tag.put("natural", new ByteTag((byte) 0)); + tag.put("ambient_light", new FloatTag(0.1F)); + tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether")); + tag.put("respawn_anchor_works", new ByteTag((byte) 1)); + tag.put("has_skylight", new ByteTag((byte) 0)); + tag.put("bed_works", new ByteTag((byte) 0)); + tag.put("fixed_time", new LongTag(18000)); + tag.put("has_raids", new ByteTag((byte) 0)); + tag.put("name", new StringTag("minecraft:the_nether")); + tag.put("logical_height", new IntTag(128)); + tag.put("shrunk", new ByteTag((byte) 1)); + tag.put("ultrawarm", new ByteTag((byte) 1)); + tag.put("has_ceiling", new ByteTag((byte) 1)); + return tag; + } + + private static CompoundTag createEndEntry() { + CompoundTag tag = new CompoundTag(); + tag.put("piglin_safe", new ByteTag((byte) 0)); + tag.put("natural", new ByteTag((byte) 0)); + tag.put("ambient_light", new FloatTag(0)); + tag.put("infiniburn", new StringTag("minecraft:infiniburn_end")); + tag.put("respawn_anchor_works", new ByteTag((byte) 0)); + tag.put("has_skylight", new ByteTag((byte) 0)); + tag.put("bed_works", new ByteTag((byte) 0)); + tag.put("fixed_time", new LongTag(6000)); + tag.put("has_raids", new ByteTag((byte) 1)); + tag.put("name", new StringTag("minecraft:the_end")); + tag.put("logical_height", new IntTag(256)); + tag.put("shrunk", new ByteTag((byte) 0)); + tag.put("ultrawarm", new ByteTag((byte) 0)); + tag.put("has_ceiling", new ByteTag((byte) 0)); + return tag; + } + +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/metadata/MetadataRewriter1_16To1_15_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/metadata/MetadataRewriter1_16To1_15_2.java deleted file mode 100644 index 715d43649..000000000 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/metadata/MetadataRewriter1_16To1_15_2.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2024 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.protocols.v1_15_2to1_16.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; -import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.type.types.version.Types1_16; -import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_16To1_15_2 extends EntityRewriter { - - public MetadataRewriter1_16To1_15_2(Protocol1_15_2To1_16 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - filter().mapMetaType(Types1_16.META_TYPES::byId); - registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType); - filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8); - filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { - byte mask = meta.value(); - int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0; - event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime)); - }); - } - - @Override - public void onMappingDataLoaded() { - mapTypes(); - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_16.getTypeFromId(type); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/TranslationMappings.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ComponentRewriter1_16.java similarity index 95% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/TranslationMappings.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ComponentRewriter1_16.java index dd688cab8..cb4162690 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/data/TranslationMappings.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ComponentRewriter1_16.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.protocols.v1_15_2to1_16.data; +package com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -27,10 +27,10 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter; import java.util.HashMap; import java.util.Map; -public class TranslationMappings extends ComponentRewriter { +public class ComponentRewriter1_16 extends ComponentRewriter { private final Map mappings = new HashMap<>(); - public TranslationMappings(Protocol1_15_2To1_16 protocol) { + public ComponentRewriter1_16(Protocol1_15_2To1_16 protocol) { super(protocol, ReadType.JSON); mappings.put("attribute.name.generic.armorToughness", "attribute.name.generic.armor_toughness"); mappings.put("attribute.name.generic.attackDamage", "attribute.name.generic.attack_damage"); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java index 2421c4e72..c7990192b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java @@ -17,34 +17,28 @@ */ package com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter; -import com.viaversion.nbt.tag.ByteTag; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.FloatTag; -import com.viaversion.nbt.tag.IntTag; -import com.viaversion.nbt.tag.ListTag; -import com.viaversion.nbt.tag.LongTag; -import com.viaversion.nbt.tag.StringTag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.minecraft.WorldIdentifiers; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; +import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.AttributeMappings; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.metadata.MetadataRewriter1_16To1_15_2; +import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.Attributes1_16; +import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.DimensionRegistries1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16; +import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.Key; -import java.util.Arrays; import java.util.UUID; -public class EntityPacketRewriter1_16 { +public class EntityPacketRewriter1_16 extends EntityRewriter { private static final PacketHandler DIMENSION_HANDLER = wrapper -> { WorldIdentifiers map = Via.getConfig().get1_16WorldNamesMap(); @@ -77,89 +71,13 @@ public class EntityPacketRewriter1_16 { wrapper.write(Types.STRING, dimensionName); // dimension wrapper.write(Types.STRING, outputName); // world }; - public static final CompoundTag DIMENSIONS_TAG = new CompoundTag(); - private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"}; - static { - ListTag list = new ListTag<>(CompoundTag.class); - list.add(createOverworldEntry()); - list.add(createOverworldCavesEntry()); - list.add(createNetherEntry()); - list.add(createEndEntry()); - DIMENSIONS_TAG.put("dimension", list); + public EntityPacketRewriter1_16(Protocol1_15_2To1_16 protocol) { + super(protocol); } - private static CompoundTag createOverworldEntry() { - CompoundTag tag = new CompoundTag(); - tag.put("name", new StringTag("minecraft:overworld")); - tag.put("has_ceiling", new ByteTag((byte) 0)); - addSharedOverwaldEntries(tag); - return tag; - } - - private static CompoundTag createOverworldCavesEntry() { - CompoundTag tag = new CompoundTag(); - tag.put("name", new StringTag("minecraft:overworld_caves")); - tag.put("has_ceiling", new ByteTag((byte) 1)); - addSharedOverwaldEntries(tag); - return tag; - } - - private static void addSharedOverwaldEntries(CompoundTag tag) { - tag.put("piglin_safe", new ByteTag((byte) 0)); - tag.put("natural", new ByteTag((byte) 1)); - tag.put("ambient_light", new FloatTag(0)); - tag.put("infiniburn", new StringTag("minecraft:infiniburn_overworld")); - tag.put("respawn_anchor_works", new ByteTag((byte) 0)); - tag.put("has_skylight", new ByteTag((byte) 1)); - tag.put("bed_works", new ByteTag((byte) 1)); - tag.put("has_raids", new ByteTag((byte) 1)); - tag.put("logical_height", new IntTag(256)); - tag.put("shrunk", new ByteTag((byte) 0)); - tag.put("ultrawarm", new ByteTag((byte) 0)); - } - - private static CompoundTag createNetherEntry() { - CompoundTag tag = new CompoundTag(); - tag.put("piglin_safe", new ByteTag((byte) 1)); - tag.put("natural", new ByteTag((byte) 0)); - tag.put("ambient_light", new FloatTag(0.1F)); - tag.put("infiniburn", new StringTag("minecraft:infiniburn_nether")); - tag.put("respawn_anchor_works", new ByteTag((byte) 1)); - tag.put("has_skylight", new ByteTag((byte) 0)); - tag.put("bed_works", new ByteTag((byte) 0)); - tag.put("fixed_time", new LongTag(18000)); - tag.put("has_raids", new ByteTag((byte) 0)); - tag.put("name", new StringTag("minecraft:the_nether")); - tag.put("logical_height", new IntTag(128)); - tag.put("shrunk", new ByteTag((byte) 1)); - tag.put("ultrawarm", new ByteTag((byte) 1)); - tag.put("has_ceiling", new ByteTag((byte) 1)); - return tag; - } - - private static CompoundTag createEndEntry() { - CompoundTag tag = new CompoundTag(); - tag.put("piglin_safe", new ByteTag((byte) 0)); - tag.put("natural", new ByteTag((byte) 0)); - tag.put("ambient_light", new FloatTag(0)); - tag.put("infiniburn", new StringTag("minecraft:infiniburn_end")); - tag.put("respawn_anchor_works", new ByteTag((byte) 0)); - tag.put("has_skylight", new ByteTag((byte) 0)); - tag.put("bed_works", new ByteTag((byte) 0)); - tag.put("fixed_time", new LongTag(6000)); - tag.put("has_raids", new ByteTag((byte) 1)); - tag.put("name", new StringTag("minecraft:the_end")); - tag.put("logical_height", new IntTag(256)); - tag.put("shrunk", new ByteTag((byte) 0)); - tag.put("ultrawarm", new ByteTag((byte) 0)); - tag.put("has_ceiling", new ByteTag((byte) 0)); - return tag; - } - - public static void register(Protocol1_15_2To1_16 protocol) { - MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class); - + @Override + protected void registerPackets() { // Spawn lightning -> Spawn entity protocol.registerClientbound(ClientboundPackets1_15.ADD_GLOBAL_ENTITY, ClientboundPackets1_16.ADD_ENTITY, wrapper -> { int entityId = wrapper.passthrough(Types.VAR_INT); @@ -186,11 +104,11 @@ public class EntityPacketRewriter1_16 { wrapper.write(Types.SHORT, (short) 0); // velocity }); - metadataRewriter.registerTrackerWithData(ClientboundPackets1_15.ADD_ENTITY, EntityTypes1_16.FALLING_BLOCK); - metadataRewriter.registerTracker(ClientboundPackets1_15.ADD_MOB); - metadataRewriter.registerTracker(ClientboundPackets1_15.ADD_PLAYER, EntityTypes1_16.PLAYER); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_15.SET_ENTITY_DATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_15.REMOVE_ENTITIES); + registerTrackerWithData(ClientboundPackets1_15.ADD_ENTITY, EntityTypes1_16.FALLING_BLOCK); + registerTracker(ClientboundPackets1_15.ADD_MOB); + registerTracker(ClientboundPackets1_15.ADD_PLAYER, EntityTypes1_16.PLAYER); + registerMetadataRewriter(ClientboundPackets1_15.SET_ENTITY_DATA, Types1_14.METADATA_LIST, Types1_16.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_15.REMOVE_ENTITIES); protocol.registerClientbound(ClientboundPackets1_15.RESPAWN, new PacketHandlers() { @Override @@ -216,8 +134,8 @@ public class EntityPacketRewriter1_16 { map(Types.UNSIGNED_BYTE); // Gamemode handler(wrapper -> { wrapper.write(Types.BYTE, (byte) -1); // Previous gamemode, set to none - wrapper.write(Types.STRING_ARRAY, Arrays.copyOf(WORLD_NAMES, WORLD_NAMES.length)); // World list - only used for command completion - wrapper.write(Types.NAMED_COMPOUND_TAG, DIMENSIONS_TAG.copy()); // Dimension registry + wrapper.write(Types.STRING_ARRAY, DimensionRegistries1_16.getWorldNames()); // World list - only used for command completion + wrapper.write(Types.NAMED_COMPOUND_TAG, DimensionRegistries1_16.getDimensionsTag()); // Dimension registry }); handler(DIMENSION_HANDLER); // Dimension map(Types.LONG); // Seed @@ -243,7 +161,7 @@ public class EntityPacketRewriter1_16 { for (int i = 0; i < size; i++) { // Attributes have been renamed and are now namespaced identifiers String key = wrapper.read(Types.STRING); - String attributeIdentifier = AttributeMappings.attributeIdentifierMappings().get(key); + String attributeIdentifier = Attributes1_16.attributeIdentifierMappings().get(key); if (attributeIdentifier == null) { attributeIdentifier = Key.namespaced(key); if (!Key.isValid(attributeIdentifier)) { @@ -285,4 +203,30 @@ public class EntityPacketRewriter1_16 { } }); } + + @Override + protected void registerRewrites() { + filter().mapMetaType(Types1_16.META_TYPES::byId); + registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType); + filter().type(EntityTypes1_16.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { + int data = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8); + filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { + byte mask = meta.value(); + int angerTime = (mask & 0x02) != 0 ? Integer.MAX_VALUE : 0; + event.createExtraMeta(new Metadata(20, Types1_16.META_TYPES.varIntType, angerTime)); + }); + } + + @Override + public void onMappingDataLoaded() { + mapTypes(); + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_16.getTypeFromId(type); + } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ItemPacketRewriter1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ItemPacketRewriter1_16.java index a210dee9b..3359a92f3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ItemPacketRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/ItemPacketRewriter1_16.java @@ -27,11 +27,10 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.AttributeMappings; +import com.viaversion.viaversion.protocols.v1_15_2to1_16.data.Attributes1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.storage.InventoryTracker1_16; @@ -240,8 +239,8 @@ public class ItemPacketRewriter1_16 extends ItemRewriter { public static final MappingData1_16_2 MAPPINGS = new MappingData1_16_2(); - private final MetadataRewriter1_16_2To1_16_1 metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this); + private final EntityPacketRewriter1_16_2 entityRewriter = new EntityPacketRewriter1_16_2(this); private final ItemPacketRewriter1_16_2 itemRewriter = new ItemPacketRewriter1_16_2(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); @@ -52,7 +50,6 @@ public class Protocol1_16_1To1_16_2 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.v1_16_1to1_16_2.metadata; - -import com.viaversion.viaversion.api.minecraft.entities.EntityType; -import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2; -import com.viaversion.viaversion.api.type.types.version.Types1_16; -import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; -import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.Protocol1_16_1To1_16_2; -import com.viaversion.viaversion.rewriter.EntityRewriter; - -public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter { - - public MetadataRewriter1_16_2To1_16_1(Protocol1_16_1To1_16_2 protocol) { - super(protocol); - } - - @Override - protected void registerRewrites() { - registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType); - filter().type(EntityTypes1_16_2.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> { - if (meta.id() == 15) { - meta.setId(16); - } else if (meta.id() == 16) { - meta.setId(15); - } - }); - } - - @Override - public void onMappingDataLoaded() { - mapTypes(); - } - - @Override - public EntityType typeFromId(int type) { - return EntityTypes1_16_2.getTypeFromId(type); - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java index 223fca082..c0be348da 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java @@ -19,24 +19,28 @@ package com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter; import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.Protocol1_16_1To1_16_2; -import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.metadata.MetadataRewriter1_16_2To1_16_1; +import com.viaversion.viaversion.rewriter.EntityRewriter; -public class EntityPacketRewriter1_16_2 { +public class EntityPacketRewriter1_16_2 extends EntityRewriter { - public static void register(Protocol1_16_1To1_16_2 protocol) { - MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class); - metadataRewriter.registerTrackerWithData(ClientboundPackets1_16.ADD_ENTITY, EntityTypes1_16_2.FALLING_BLOCK); - metadataRewriter.registerTracker(ClientboundPackets1_16.ADD_MOB); - metadataRewriter.registerTracker(ClientboundPackets1_16.ADD_PLAYER, EntityTypes1_16_2.PLAYER); - metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.SET_ENTITY_DATA, Types1_16.METADATA_LIST); - metadataRewriter.registerRemoveEntities(ClientboundPackets1_16.REMOVE_ENTITIES); + public EntityPacketRewriter1_16_2(Protocol1_16_1To1_16_2 protocol) { + super(protocol); + } + + @Override + protected void registerPackets() { + registerTrackerWithData(ClientboundPackets1_16.ADD_ENTITY, EntityTypes1_16_2.FALLING_BLOCK); + registerTracker(ClientboundPackets1_16.ADD_MOB); + registerTracker(ClientboundPackets1_16.ADD_PLAYER, EntityTypes1_16_2.PLAYER); + registerMetadataRewriter(ClientboundPackets1_16.SET_ENTITY_DATA, Types1_16.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_16.REMOVE_ENTITIES); protocol.registerClientbound(ClientboundPackets1_16.LOGIN, new PacketHandlers() { @Override @@ -62,7 +66,7 @@ public class EntityPacketRewriter1_16_2 { map(Types.LONG); // Seed map(Types.UNSIGNED_BYTE, Types.VAR_INT); // Max players // ... - handler(metadataRewriter.playerTrackerHandler()); + handler(playerTrackerHandler()); } }); @@ -72,7 +76,34 @@ public class EntityPacketRewriter1_16_2 { }); } - public static CompoundTag getDimensionData(String dimensionType) { + @Override + protected void registerRewrites() { + registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.optionalBlockStateType, Types1_16.META_TYPES.particleType); + filter().type(EntityTypes1_16_2.ABSTRACT_MINECART).index(10).handler((metadatas, meta) -> { + int data = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> { + if (meta.id() == 15) { + meta.setId(16); + } else if (meta.id() == 16) { + meta.setId(15); + } + }); + } + + @Override + public void onMappingDataLoaded() { + mapTypes(); + } + + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_16_2.getTypeFromId(type); + } + + + private CompoundTag getDimensionData(String dimensionType) { CompoundTag tag = Protocol1_16_1To1_16_2.MAPPINGS.getDimensionDataMap().get(dimensionType); if (tag == null) { Via.getPlatform().getLogger().severe("Could not get dimension data of " + dimensionType); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities1_18.java similarity index 98% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities1_18.java index fe318e1d2..d90c38321 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntities1_18.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_17_1to1_18.data; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -public final class BlockEntities { +public final class BlockEntities1_18 { private static final Object2IntMap BLOCK_ENTITY_IDS = new Object2IntOpenHashMap<>(); static { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds1_18.java similarity index 97% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds1_18.java index 72e821196..a53a06de0 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/data/BlockEntityIds1_18.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_17_1to1_18.data; import com.viaversion.viaversion.api.Via; import java.util.Arrays; -public final class BlockEntityIds { +public final class BlockEntityIds1_18 { private static final int[] IDS = new int[14]; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/rewriter/WorldPacketRewriter1_18.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/rewriter/WorldPacketRewriter1_18.java index 9c21f9903..838689d1a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/rewriter/WorldPacketRewriter1_18.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_17_1to1_18/rewriter/WorldPacketRewriter1_18.java @@ -31,13 +31,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl; import com.viaversion.viaversion.api.minecraft.chunks.DataPaletteImpl; import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18; import com.viaversion.viaversion.protocols.v1_17_1to1_18.Protocol1_17_1To1_18; -import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntityIds; -import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntities; +import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntityIds1_18; +import com.viaversion.viaversion.protocols.v1_17_1to1_18.data.BlockEntities1_18; import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPackets1_18; import com.viaversion.viaversion.protocols.v1_17_1to1_18.storage.ChunkLightStorage; import com.viaversion.viaversion.protocols.v1_17to1_17_1.packet.ClientboundPackets1_17_1; @@ -56,7 +55,7 @@ public final class WorldPacketRewriter1_18 { map(Types.BLOCK_POSITION1_14); handler(wrapper -> { final short id = wrapper.read(Types.UNSIGNED_BYTE); - final int newId = BlockEntityIds.newId(id); + final int newId = BlockEntityIds1_18.newId(id); wrapper.write(Types.VAR_INT, newId); handleSpawners(newId, wrapper.passthrough(Types.NAMED_COMPOUND_TAG)); @@ -118,7 +117,7 @@ public final class WorldPacketRewriter1_18 { } final String id = idTag.getValue(); - final int typeId = BlockEntities.blockEntityIds().getInt(Key.stripMinecraftNamespace(id)); + final int typeId = BlockEntities1_18.blockEntityIds().getInt(Key.stripMinecraftNamespace(id)); if (typeId == -1) { Via.getPlatform().getLogger().warning("Unknown block entity: " + id); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/Protocol1_18_2To1_19.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/Protocol1_18_2To1_19.java index 8dd6d92cc..25221d1d8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/Protocol1_18_2To1_19.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/Protocol1_18_2To1_19.java @@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_19; @@ -43,7 +42,7 @@ import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.EntityPacketRe import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.ItemPacketRewriter1_19; import com.viaversion.viaversion.protocols.v1_18_2to1_19.rewriter.WorldPacketRewriter1_19; import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.DimensionRegistryStorage; -import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.NonceStorage; +import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.NonceStorage1_19; import com.viaversion.viaversion.protocols.v1_18_2to1_19.storage.SequenceStorage; import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -249,7 +248,7 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol { final byte[] publicKey = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE); final byte[] nonce = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE); - wrapper.user().put(new NonceStorage(CipherUtil.encryptNonce(publicKey, nonce))); + wrapper.user().put(new NonceStorage1_19(CipherUtil.encryptNonce(publicKey, nonce))); }); } }); @@ -272,7 +271,7 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol dimensions; public @Nullable String dimensionKey(final CompoundTag dimensionData) { - return dimensions.get(dimensionData); // HMMMMMMMMMMM + return dimensions.get(dimensionData); } public void setDimensions(final Map dimensions) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage1_19.java similarity index 92% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage1_19.java index 3f759db2b..bcb865f28 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/storage/NonceStorage1_19.java @@ -19,5 +19,5 @@ package com.viaversion.viaversion.protocols.v1_18_2to1_19.storage; import com.viaversion.viaversion.api.connection.StorableObject; -public record NonceStorage(byte[] nonce) implements StorableObject { +public record NonceStorage1_19(byte[] nonce) implements StorableObject { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/Protocol1_19_1To1_19_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/Protocol1_19_1To1_19_3.java index f9069ec19..e9736fd25 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/Protocol1_19_1To1_19_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/Protocol1_19_1To1_19_3.java @@ -37,9 +37,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; -import com.viaversion.viaversion.api.type.types.BitSetType; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_19_3; import com.viaversion.viaversion.data.entity.EntityTrackerBase; @@ -51,7 +49,7 @@ import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPacke import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.EntityPacketRewriter1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.ItemPacketRewriter1_19_3; -import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage; +import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.ReceivedMessagesStorage; import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; @@ -294,7 +292,7 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol { if (wrapper.user().has(ChatSession1_19_1.class)) { - wrapper.user().put(new NonceStorage(wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE))); // Nonce + wrapper.user().put(new NonceStorage1_19_3(wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE))); // Nonce } }); } @@ -324,7 +322,7 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol { - signer.accept(wrapper.user().remove(NonceStorage.class).nonce()); + signer.accept(wrapper.user().remove(NonceStorage1_19_3.class).nonce()); signer.accept(Longs.toByteArray(salt)); }); } catch (final SignatureException e) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage1_19_3.java similarity index 92% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage1_19_3.java index 77abb7f12..84490434d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/storage/NonceStorage1_19_3.java @@ -20,5 +20,5 @@ package com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage; import com.viaversion.viaversion.api.connection.StorableObject; import org.checkerframework.checker.nullness.qual.Nullable; -public record NonceStorage(byte @Nullable[] nonce) implements StorableObject { +public record NonceStorage1_19_3(byte @Nullable[] nonce) implements StorableObject { } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/Protocol1_19To1_19_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/Protocol1_19To1_19_1.java index 311860d9a..3d639848b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/Protocol1_19To1_19_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/Protocol1_19To1_19_1.java @@ -34,18 +34,17 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19 import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19; import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ServerboundPackets1_19; import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatDecorationResult; -import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatRegistry; +import com.viaversion.viaversion.protocols.v1_19to1_19_1.data.ChatRegistry1_19_1; import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1; import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1; import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.ChatTypeStorage; -import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.NonceStorage; +import com.viaversion.viaversion.protocols.v1_19to1_19_1.storage.NonceStorage1_19_1; import com.viaversion.viaversion.util.CipherUtil; import com.viaversion.viaversion.util.Pair; import com.viaversion.viaversion.util.TagUtil; @@ -211,7 +210,7 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol1.19 protocol; no need to map it - wrapper.user().put(new NonceStorage(null)); + wrapper.user().put(new NonceStorage1_19_1(null)); } }); read(Types.OPTIONAL_UUID); // Profile uuid @@ -249,13 +248,13 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol { - if (wrapper.user().has(NonceStorage.class)) { + if (wrapper.user().has(NonceStorage1_19_1.class)) { return; } final byte[] publicKey = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE); final byte[] nonce = wrapper.passthrough(Types.BYTE_ARRAY_PRIMITIVE); - wrapper.user().put(new NonceStorage(CipherUtil.encryptNonce(publicKey, nonce))); + wrapper.user().put(new NonceStorage1_19_1(CipherUtil.encryptNonce(publicKey, nonce))); }); } }); @@ -264,7 +263,7 @@ public final class Protocol1_19To1_19_1 extends AbstractProtocol { - final NonceStorage nonceStorage = wrapper.user().remove(NonceStorage.class); + final NonceStorage1_19_1 nonceStorage = wrapper.user().remove(NonceStorage1_19_1.class); if (nonceStorage.nonce() == null) { return; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry1_19_1.java similarity index 97% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry1_19_1.java index ebfd592e9..4ed7b30c2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/data/ChatRegistry1_19_1.java @@ -20,7 +20,7 @@ package com.viaversion.viaversion.protocols.v1_19to1_19_1.data; import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.viaversion.api.data.MappingDataLoader; -public class ChatRegistry { +public class ChatRegistry1_19_1 { private static final CompoundTag chatRegistry; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage1_19_1.java similarity index 91% rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage.java rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage1_19_1.java index 3ba9c27b5..49d57abf4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19to1_19_1/storage/NonceStorage1_19_1.java @@ -20,6 +20,6 @@ package com.viaversion.viaversion.protocols.v1_19to1_19_1.storage; import com.viaversion.viaversion.api.connection.StorableObject; import org.checkerframework.checker.nullness.qual.Nullable; -public record NonceStorage(byte @Nullable [] nonce) implements StorableObject { +public record NonceStorage1_19_1(byte @Nullable [] nonce) implements StorableObject { }