diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java index a7160e5b..b1f242e1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -49,6 +49,7 @@ import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2; import com.viaversion.viabackwards.protocol.v1_18_2to1_18.Protocol1_18_2To1_18; import com.viaversion.viabackwards.protocol.v1_19_3to1_19_1.Protocol1_19_3To1_19_1; import com.viaversion.viabackwards.protocol.v1_19_4to1_19_3.Protocol1_19_4To1_19_3; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2; import com.viaversion.viabackwards.protocol.v1_20to1_19_4.Protocol1_20To1_19_4; import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19; import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2; @@ -71,7 +72,7 @@ import java.util.logging.Logger; public interface ViaBackwardsPlatform { - String MINIMUM_VV_VERSION = "5.1.2"; + String MINIMUM_VV_VERSION = "5.2.0"; /** * Initialize ViaBackwards. @@ -144,6 +145,7 @@ public interface ViaBackwardsPlatform { protocolManager.registerProtocol(new Protocol1_21To1_20_5(), ProtocolVersion.v1_20_5, ProtocolVersion.v1_21); protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2); + protocolManager.registerProtocol(new Protocol1_21_4To1_21_2(), ProtocolVersion.v1_21_2, ProtocolVersion.v1_21_4); } default void enable() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java index d06073ca..7aaded18 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/BlockItemPacketRewriter1_99.java @@ -37,8 +37,7 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter< super(protocol, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY); /*super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, - Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST, - Types1_21.PARTICLE, Types1_OLD.PARTICLE + Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST );*/ } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java index 1a27d30b..6628f7d1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/ComponentRewriter1_99.java @@ -24,7 +24,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; import com.viaversion.viaversion.util.SerializerVersion; -public class ComponentRewriter1_99 extends TranslatableRewriter { +final class ComponentRewriter1_99 extends TranslatableRewriter { public ComponentRewriter1_99(final BackwardsProtocol protocol) { super(protocol, ReadType.NBT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java index 39865c8b..60152565 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/template/Protocol1_98To1_99.java @@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.template; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappingData; import com.viaversion.viabackwards.api.rewriters.SoundRewriter; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; @@ -56,7 +57,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol particleRewriter = new ParticleRewriter<>(this, Types1_21_2.PARTICLE/*, Types1_OLD.PARTICLE*/); - private final ComponentRewriter1_99 translatableRewriter = new ComponentRewriter1_99(this); + private final TranslatableRewriter translatableRewriter = new ComponentRewriter1_99(this); private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_98To1_99() { @@ -89,7 +90,7 @@ final class Protocol1_98To1_99 extends BackwardsProtocol getComponentRewriter() { return translatableRewriter; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/Protocol1_21_4To1_21_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/Protocol1_21_4To1_21_2.java new file mode 100644 index 00000000..cba8eeba --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/Protocol1_21_4To1_21_2.java @@ -0,0 +1,207 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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.viabackwards.protocol.v1_21_4to1_21_2; + +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.data.BackwardsMappingData; +import com.viaversion.viabackwards.api.rewriters.SoundRewriter; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.rewriter.BlockItemPacketRewriter1_21_4; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.rewriter.ComponentRewriter1_21_4; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.rewriter.EntityPacketRewriter1_99; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.rewriter.ParticleRewriter1_21_4; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; +import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; +import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; +import com.viaversion.viaversion.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.Protocol1_21_2To1_21_4; +import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPacket1_21_4; +import com.viaversion.viaversion.protocols.v1_21_2to1_21_4.packet.ServerboundPackets1_21_4; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import com.viaversion.viaversion.rewriter.AttributeRewriter; +import com.viaversion.viaversion.rewriter.ParticleRewriter; +import com.viaversion.viaversion.rewriter.StatisticsRewriter; +import com.viaversion.viaversion.rewriter.TagRewriter; +import java.util.BitSet; + +import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; + +public final class Protocol1_21_4To1_21_2 extends BackwardsProtocol { + + public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.21.4", "1.21.2", Protocol1_21_2To1_21_4.class); + private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this); + private final BlockItemPacketRewriter1_21_4 itemRewriter = new BlockItemPacketRewriter1_21_4(this); + private final ParticleRewriter particleRewriter = new ParticleRewriter1_21_4(this); + private final TranslatableRewriter translatableRewriter = new ComponentRewriter1_21_4(this); + private final TagRewriter tagRewriter = new TagRewriter<>(this); + + public Protocol1_21_4To1_21_2() { + super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_4.class, ServerboundPacket1_21_2.class); + } + + @Override + protected void registerPackets() { + super.registerPackets(); + + tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS); + + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY); + soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND); + + new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS); + new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES); + + translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT); + translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT); + translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST); + translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT); + translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISGUISED_CHAT); + translatableRewriter.registerPing(); + + particleRewriter.registerExplode1_21_2(ClientboundPackets1_21_2.EXPLODE); + registerClientbound(ClientboundPackets1_21_2.LEVEL_PARTICLES, wrapper -> { + wrapper.passthrough(Types.BOOLEAN); // Override limiter + wrapper.read(Types.BOOLEAN); // Always show + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.FLOAT); // Offset X + wrapper.passthrough(Types.FLOAT); // Offset Y + wrapper.passthrough(Types.FLOAT); // Offset Z + wrapper.passthrough(Types.FLOAT); // Particle Data + wrapper.passthrough(Types.INT); // Particle Count + final Particle particle = wrapper.passthroughAndMap(Types1_21_4.PARTICLE, Types1_21_2.PARTICLE); + particleRewriter.rewriteParticle(wrapper.user(), particle); + }); + + registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> { + final BitSet actions = wrapper.read(Types.PROFILE_ACTIONS_ENUM1_21_4); + // Remove new action + final BitSet updatedActions = new BitSet(7); + for (int i = 0; i < 7; i++) { + if (actions.get(i)) { + updatedActions.set(i); + } + } + wrapper.write(Types.PROFILE_ACTIONS_ENUM1_21_2, updatedActions); + + final int entries = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < entries; i++) { + wrapper.passthrough(Types.UUID); + if (actions.get(0)) { + wrapper.passthrough(Types.STRING); // Player Name + + final int properties = wrapper.passthrough(Types.VAR_INT); + for (int j = 0; j < properties; j++) { + wrapper.passthrough(Types.STRING); // Name + wrapper.passthrough(Types.STRING); // Value + wrapper.passthrough(Types.OPTIONAL_STRING); // Signature + } + } + if (actions.get(1) && wrapper.passthrough(Types.BOOLEAN)) { + wrapper.passthrough(Types.UUID); // Session UUID + wrapper.passthrough(Types.PROFILE_KEY); + } + if (actions.get(2)) { + wrapper.passthrough(Types.VAR_INT); // Gamemode + } + if (actions.get(3)) { + wrapper.passthrough(Types.BOOLEAN); // Listed + } + if (actions.get(4)) { + wrapper.passthrough(Types.VAR_INT); // Latency + } + if (actions.get(5)) { + translatableRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_TAG)); + } + if (actions.get(6)) { + actions.clear(6); + wrapper.passthrough(Types.VAR_INT); // List order + } + + // Remove + if (actions.get(7)) { + wrapper.read(Types.BOOLEAN); // Show head + } + } + }); + } + + @Override + public void init(final UserConnection user) { + addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_21_2.PLAYER)); + } + + @Override + public BackwardsMappingData getMappingData() { + return MAPPINGS; + } + + @Override + public EntityPacketRewriter1_99 getEntityRewriter() { + return entityRewriter; + } + + @Override + public BlockItemPacketRewriter1_21_4 getItemRewriter() { + return itemRewriter; + } + + @Override + public ParticleRewriter getParticleRewriter() { + return particleRewriter; + } + + @Override + public TranslatableRewriter getComponentRewriter() { + return translatableRewriter; + } + + @Override + public TagRewriter getTagRewriter() { + return tagRewriter; + } + + @Override + protected PacketTypesProvider createPacketTypesProvider() { + return new SimplePacketTypesProvider<>( + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_4.class, ServerboundConfigurationPackets1_20_5.class), + packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class) + ); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java new file mode 100644 index 00000000..599e5c63 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/BlockItemPacketRewriter1_21_4.java @@ -0,0 +1,75 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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.viabackwards.protocol.v1_21_4to1_21_2.rewriter; + +import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2; +import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter; + +public final class BlockItemPacketRewriter1_21_4 extends BackwardsStructuredItemRewriter { + + public BlockItemPacketRewriter1_21_4(final Protocol1_21_4To1_21_2 protocol) { + super(protocol, + Types1_21_4.ITEM, Types1_21_4.ITEM_ARRAY, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY, + Types1_21_4.ITEM_COST, Types1_21_4.OPTIONAL_ITEM_COST, Types1_21_2.ITEM_COST, Types1_21_2.OPTIONAL_ITEM_COST + ); + } + + @Override + public void registerPackets() { + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT); + blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE); + blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE); + blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001); + blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); + blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA); + + protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, wrapper -> { + final int slot = wrapper.read(Types.VAR_INT); + wrapper.write(Types.BYTE, (byte) slot); + }); + + protocol.cancelServerbound(ServerboundPackets1_21_2.PICK_ITEM); + + protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem); + registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN); + registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT); + registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT); + registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS); + registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT); + registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS); + registerContainerSetData(ClientboundPackets1_21_2.CONTAINER_SET_DATA); + registerContainerClick1_21_2(ServerboundPackets1_21_2.CONTAINER_CLICK); + registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT); + + final RecipeDisplayRewriter recipeRewriter = new RecipeDisplayRewriter<>(protocol); + recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES); + recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_2.RECIPE_BOOK_ADD); + recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ComponentRewriter1_21_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ComponentRewriter1_21_4.java new file mode 100644 index 00000000..7df3333b --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ComponentRewriter1_21_4.java @@ -0,0 +1,48 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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.viabackwards.protocol.v1_21_4to1_21_2.rewriter; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.viabackwards.api.BackwardsProtocol; +import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.util.SerializerVersion; + +public final class ComponentRewriter1_21_4 extends TranslatableRewriter { + + public ComponentRewriter1_21_4(final BackwardsProtocol protocol) { + super(protocol, ReadType.NBT); + } + + @Override + protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) { + super.handleShowItem(connection, itemTag, componentsTag); + if (componentsTag == null) { + return; + } + + // Remove or update data from componentsTag + // New added data which is not handled otherwise needs to be removed to prevent errors on the client + } + + @Override + protected SerializerVersion inputSerializerVersion() { + return SerializerVersion.V1_20_5; + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/EntityPacketRewriter1_99.java new file mode 100644 index 00000000..1a06694a --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/EntityPacketRewriter1_99.java @@ -0,0 +1,134 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * 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.viabackwards.protocol.v1_21_4to1_21_2.rewriter; + +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.ListTag; +import com.viaversion.viabackwards.api.rewriters.EntityRewriter; +import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2; +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.RegistryEntry; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2; +import com.viaversion.viaversion.rewriter.RegistryDataRewriter; +import com.viaversion.viaversion.util.Key; + +public final class EntityPacketRewriter1_99 extends EntityRewriter { + + public EntityPacketRewriter1_99(final Protocol1_21_4To1_21_2 protocol) { + super(protocol, Types1_21_4.ENTITY_DATA_TYPES.optionalComponentType, Types1_21_4.ENTITY_DATA_TYPES.booleanType); + } + + @Override + public void registerPackets() { + registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_21_2.FALLING_BLOCK); + registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, Types1_21_4.ENTITY_DATA_LIST, Types1_21_2.ENTITY_DATA_LIST); + registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES); + + final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol) { + @Override + public RegistryEntry[] handle(final UserConnection connection, final String key, final RegistryEntry[] entries) { + if (Key.stripMinecraftNamespace(key).equals("worldgen/biome")) { + for (final RegistryEntry entry : entries) { + if (entry.tag() == null) { + continue; + } + + final CompoundTag effectsTag = ((CompoundTag) entry.tag()).getCompoundTag("effects"); + final ListTag weightedMusicTags = effectsTag.getListTag("music", CompoundTag.class); + if (weightedMusicTags == null) { + continue; + } + + if (weightedMusicTags.isEmpty()) { + effectsTag.remove("music"); + continue; + } + + // Unwrap music + final CompoundTag musicTag = weightedMusicTags.get(0); + effectsTag.put("music", musicTag.get("data")); + } + } + + return super.handle(connection, key, entries); + } + }; + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle); + + + protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, wrapper -> { + final int entityId = wrapper.passthrough(Types.INT); // Entity id + wrapper.passthrough(Types.BOOLEAN); // Hardcore + wrapper.passthrough(Types.STRING_ARRAY); // World List + wrapper.passthrough(Types.VAR_INT); // Max players + wrapper.passthrough(Types.VAR_INT); // View distance + wrapper.passthrough(Types.VAR_INT); // Simulation distance + wrapper.passthrough(Types.BOOLEAN); // Reduced debug info + wrapper.passthrough(Types.BOOLEAN); // Show death screen + wrapper.passthrough(Types.BOOLEAN); // Limited crafting + final int dimensionId = wrapper.passthrough(Types.VAR_INT); + final String world = wrapper.passthrough(Types.STRING); + trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); + trackPlayer(wrapper.user(), entityId); + }); + + protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> { + final int dimensionId = wrapper.passthrough(Types.VAR_INT); + final String world = wrapper.passthrough(Types.STRING); + trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); + }); + } + + @Override + protected void registerRewrites() { + filter().mapDataType(Types1_21_2.ENTITY_DATA_TYPES::byId); + registerEntityDataTypeHandler1_20_3( + Types1_21_2.ENTITY_DATA_TYPES.itemType, + Types1_21_2.ENTITY_DATA_TYPES.blockStateType, + Types1_21_2.ENTITY_DATA_TYPES.optionalBlockStateType, + Types1_21_2.ENTITY_DATA_TYPES.particleType, + Types1_21_2.ENTITY_DATA_TYPES.particlesType, + Types1_21_2.ENTITY_DATA_TYPES.componentType, + Types1_21_2.ENTITY_DATA_TYPES.optionalComponentType + ); + registerBlockStateHandler(EntityTypes1_21_2.ABSTRACT_MINECART, 11); + + filter().type(EntityTypes1_21_2.CREAKING_TRANSIENT).removeIndex(18); // Is tearing down + filter().type(EntityTypes1_21_2.SALMON).index(17).handler((event, data) -> { + final int typeId = data.value(); + final String type = switch (typeId) { + case 0 -> "small"; + case 2 -> "large"; + default -> "medium"; + }; + data.setTypeAndValue(Types1_21_4.ENTITY_DATA_TYPES.stringType, type); + }); + } + + @Override + public EntityType typeFromId(final int type) { + return EntityTypes1_21_2.getTypeFromId(type); + } +} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ParticleRewriter1_21_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ParticleRewriter1_21_4.java new file mode 100644 index 00000000..c8cf3d41 --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_4to1_21_2/rewriter/ParticleRewriter1_21_4.java @@ -0,0 +1,43 @@ +/* + * 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.viabackwards.protocol.v1_21_4to1_21_2.rewriter; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.Particle; +import com.viaversion.viaversion.api.protocol.Protocol; +import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; +import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2; +import com.viaversion.viaversion.rewriter.ParticleRewriter; + +public final class ParticleRewriter1_21_4 extends ParticleRewriter { + + public ParticleRewriter1_21_4(final Protocol protocol) { + super(protocol, Types1_21_4.PARTICLE, Types1_21_2.PARTICLE); + } + + @Override + public void rewriteParticle(final UserConnection connection, final Particle particle) { + super.rewriteParticle(connection, particle); + + final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id()); + if (identifier.equals("minecraft:trail")) { + particle.removeArgument(4); // Duration + } + } +} diff --git a/common/src/main/resources/assets/viabackwards/data/mappings-1.21.4to1.21.2.nbt b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.4to1.21.2.nbt new file mode 100644 index 00000000..cc1dcdbc Binary files /dev/null and b/common/src/main/resources/assets/viabackwards/data/mappings-1.21.4to1.21.2.nbt differ diff --git a/gradle.properties b/gradle.properties index f88f29d2..775814b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -projectVersion=5.1.2-SNAPSHOT +projectVersion=5.2.0-SNAPSHOT # Smile emoji mcVersions=1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f8118301..115a50c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "5.1.2-SNAPSHOT" +viaver = "5.2.0-SNAPSHOT" # Common provided netty = "4.0.20.Final" diff --git a/settings.gradle.kts b/settings.gradle.kts index 312d288c..2e2365f6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ rootProject.name = "viabackwards-parent" dependencyResolutionManagement { repositories { + mavenLocal() maven("https://repo.viaversion.com") maven("https://repo.papermc.io/repository/maven-public/") mavenCentral()