From 8670d8105dbcbb607fc58582e1e857eb61b8fb81 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 16 Feb 2023 13:10:41 +0100 Subject: [PATCH] 23w07 without mappings --- build.gradle.kts | 2 +- .../viabackwards/api/BackwardsProtocol.java | 10 +- .../api/rewriters/SoundRewriter.java | 5 + .../packets/BlockItemPackets1_14.java | 3 +- .../Protocol1_14_2To1_14_3.java | 3 +- .../packets/BlockItemPackets1_15.java | 4 +- .../packets/BlockItemPackets1_16.java | 4 +- .../packets/BlockItemPackets1_16_2.java | 4 +- .../packets/BlockItemPackets1_17.java | 4 +- .../packets/BlockItemPackets1_18.java | 4 +- .../packets/BlockItemPackets1_19.java | 4 +- .../packets/BlockItemPackets1_19_3.java | 4 +- .../Protocol1_19_3To1_19_4.java | 46 ++++---- .../packets/BlockItemPackets1_19_4.java | 101 ++++++++++++++++++ .../packets/EntityPackets1_19_4.java | 38 ++++++- 15 files changed, 186 insertions(+), 50 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java diff --git a/build.gradle.kts b/build.gradle.kts index 6810b639..ebe94560 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.6.0-23w06a-SNAPSHOT" + version = "4.6.0-23w07a-SNAPSHOT" description = "Allow older clients to join newer server versions." } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java b/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java index 0cab9bd1..6e551e9c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/BackwardsProtocol.java @@ -26,14 +26,14 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; import org.checkerframework.checker.nullness.qual.Nullable; -public abstract class BackwardsProtocol - extends AbstractProtocol { +public abstract class BackwardsProtocol + extends AbstractProtocol { protected BackwardsProtocol() { } - protected BackwardsProtocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, - @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum) { + protected BackwardsProtocol(@Nullable Class oldClientboundPacketEnum, @Nullable Class clientboundPacketEnum, + @Nullable Class oldServerboundPacketEnum, @Nullable Class serverboundPacketEnum) { super(oldClientboundPacketEnum, clientboundPacketEnum, oldServerboundPacketEnum, serverboundPacketEnum); } @@ -55,7 +55,7 @@ public abstract class BackwardsProtocol getTranslatableRewriter() { + public @Nullable TranslatableRewriter getTranslatableRewriter() { return null; } } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java index 722fb19a..93b54b3c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/SoundRewriter.java @@ -93,6 +93,11 @@ public class SoundRewriter extends com.viaversi }; } + @Override + public void register1_19_3Sound(C packetType) { + protocol.registerClientbound(packetType, get1_19_3SoundHandler()); + } + public PacketHandler get1_19_3SoundHandler() { return wrapper -> { final int soundId = wrapper.read(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index 95c5f3f0..eca6fe72 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -47,7 +47,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; -import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; @@ -254,7 +253,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit } }); - RecipeRewriter recipeHandler = new RecipeRewriter1_13_2<>(protocol); + RecipeRewriter recipeHandler = new RecipeRewriter<>(protocol); final Set removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting"); protocol.registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, wrapper -> { int size = wrapper.passthrough(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java index c851b600..7c4e8ac8 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_2to1_14_3/Protocol1_14_2To1_14_3.java @@ -21,7 +21,6 @@ import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14; import com.viaversion.viaversion.rewriter.RecipeRewriter; public class Protocol1_14_2To1_14_3 extends BackwardsProtocol { @@ -55,7 +54,7 @@ public class Protocol1_14_2To1_14_3 extends BackwardsProtocol recipeHandler = new RecipeRewriter1_14<>(this); + RecipeRewriter recipeHandler = new RecipeRewriter<>(this); registerClientbound(ClientboundPackets1_14.DECLARE_RECIPES, wrapper -> { int size = wrapper.passthrough(Type.VAR_INT); int deleted = 0; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java index b14414fd..3c444ae3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java @@ -26,11 +26,11 @@ 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.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter { @@ -42,7 +42,7 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit protected void registerPackets() { BlockRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); - new RecipeRewriter1_14<>(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES); + new RecipeRewriter<>(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES); protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM))); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 11300167..12459a0f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -39,13 +39,13 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; -import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; import com.viaversion.viaversion.util.CompactArrayUtil; import java.util.ArrayList; import java.util.List; @@ -64,7 +64,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit protected void registerPackets() { BlockRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); - RecipeRewriter1_14 recipeRewriter = new RecipeRewriter1_14<>(protocol); + RecipeRewriter recipeRewriter = new RecipeRewriter<>(protocol); // Remove new smithing type, only in this handler protocol.registerClientbound(ClientboundPackets1_16.DECLARE_RECIPES, wrapper -> { int size = wrapper.passthrough(Type.VAR_INT); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index 62417f4e..ff25a700 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -34,9 +34,9 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; -import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewriters.ItemRewriter { @@ -48,7 +48,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr protected void registerPackets() { BlockRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); - new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES); + new RecipeRewriter<>(protocol).register(ClientboundPackets1_16_2.DECLARE_RECIPES); registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN); registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java index c9fcdc5e..5b459a75 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java @@ -41,11 +41,11 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type; -import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; import com.viaversion.viaversion.util.CompactArrayUtil; import com.viaversion.viaversion.util.MathUtil; import java.util.ArrayList; @@ -63,7 +63,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); - new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_17.DECLARE_RECIPES); + new RecipeRewriter<>(protocol).register(ClientboundPackets1_17.DECLARE_RECIPES); registerSetCooldown(ClientboundPackets1_17.COOLDOWN); registerWindowItems(ClientboundPackets1_17.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java index c075d839..d614f806 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java @@ -35,12 +35,12 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; -import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type; +import com.viaversion.viaversion.rewriter.RecipeRewriter; import com.viaversion.viaversion.util.MathUtil; import java.util.ArrayList; import java.util.BitSet; @@ -54,7 +54,7 @@ public final class BlockItemPackets1_18 extends ItemRewriter(protocol).registerDefaultHandler(ClientboundPackets1_18.DECLARE_RECIPES); + new RecipeRewriter<>(protocol).register(ClientboundPackets1_18.DECLARE_RECIPES); registerSetCooldown(ClientboundPackets1_18.COOLDOWN); registerWindowItems1_17_1(ClientboundPackets1_18.WINDOW_ITEMS); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java index 370aa249..35890b53 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_18_2to1_19/packets/BlockItemPackets1_19.java @@ -29,11 +29,11 @@ import com.viaversion.viaversion.api.minecraft.item.Item; 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.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; import com.viaversion.viaversion.util.MathUtil; public final class BlockItemPackets1_19 extends ItemRewriter { @@ -46,7 +46,7 @@ public final class BlockItemPackets1_19 extends ItemRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); - new RecipeRewriter1_16<>(protocol).registerDefaultHandler(ClientboundPackets1_19.DECLARE_RECIPES); + new RecipeRewriter<>(protocol).register(ClientboundPackets1_19.DECLARE_RECIPES); registerSetCooldown(ClientboundPackets1_19.COOLDOWN); registerWindowItems1_17_1(ClientboundPackets1_19.WINDOW_ITEMS); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java index 1d64e72c..ec5fd001 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_1to1_19_3/packets/BlockItemPackets1_19_3.java @@ -22,11 +22,11 @@ import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_ 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.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type; import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.ServerboundPackets1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.RecipeRewriter; public final class BlockItemPackets1_19_3 extends ItemRewriter { @@ -64,7 +64,7 @@ public final class BlockItemPackets1_19_3 extends ItemRewriter recipeRewriter = new RecipeRewriter1_16<>(protocol); + final RecipeRewriter recipeRewriter = new RecipeRewriter<>(protocol); protocol.registerClientbound(ClientboundPackets1_19_3.DECLARE_RECIPES, wrapper -> { final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java index 2b1bf760..dd1a2ee1 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/Protocol1_19_3To1_19_4.java @@ -20,13 +20,14 @@ package com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.data.BackwardsMappings; import com.viaversion.viabackwards.api.rewriters.ItemRewriter; +import com.viaversion.viabackwards.api.rewriters.SoundRewriter; import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.packets.EntityPackets1_19_4; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; 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.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.libs.gson.JsonElement; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; @@ -34,6 +35,8 @@ import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4 import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; +import java.nio.charset.StandardCharsets; +import java.util.Base64; public final class Protocol1_19_3To1_19_4 extends BackwardsProtocol { @@ -55,7 +58,12 @@ public final class Protocol1_19_3To1_19_4 extends BackwardsProtocol commandRewriter = new CommandRewriter(this) { + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.registerStopSound(ClientboundPackets1_19_4.STOP_SOUND); + soundRewriter.register1_19_3Sound(ClientboundPackets1_19_4.SOUND); + soundRewriter.register1_19_3Sound(ClientboundPackets1_19_4.ENTITY_SOUND); + + new CommandRewriter(this) { @Override public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { if (argumentType.equals("minecraft:time")) { @@ -68,33 +76,22 @@ public final class Protocol1_19_3To1_19_4 extends BackwardsProtocol tagRewriter = new TagRewriter<>(this); tagRewriter.removeTags("minecraft:damage_type"); tagRewriter.registerGeneric(ClientboundPackets1_19_4.TAGS); - cancelClientbound(ClientboundPackets1_19_4.BUNDLE); + registerClientbound(ClientboundPackets1_19_4.SERVER_DATA, wrapper -> { + final JsonElement element = wrapper.read(Type.COMPONENT); + wrapper.write(Type.OPTIONAL_COMPONENT, element); - registerClientbound(ClientboundPackets1_19_4.DAMAGE_EVENT, ClientboundPackets1_19_3.ENTITY_STATUS, new PacketHandlers() { - @Override - public void register() { - map(Type.VAR_INT, Type.INT); // Entity id - read(Type.VAR_INT); // Damage type - read(Type.VAR_INT); // Cause entity - read(Type.VAR_INT); // Direct cause entity - handler(wrapper -> { - // Source position - if (wrapper.read(Type.BOOLEAN)) { - wrapper.read(Type.DOUBLE); - wrapper.read(Type.DOUBLE); - wrapper.read(Type.DOUBLE); - } - }); - create(Type.BYTE, (byte) 2); // Generic hurt - } + final byte[] iconBytes = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE); + final String iconBase64 = "data:image/png;base64," + new String(Base64.getEncoder().encode(iconBytes), StandardCharsets.UTF_8); + wrapper.write(Type.STRING, iconBase64); }); + + cancelClientbound(ClientboundPackets1_19_4.BUNDLE); } @Override @@ -111,4 +108,9 @@ public final class Protocol1_19_3To1_19_4 extends BackwardsProtocol getItemRewriter() { return itemRewriter; } + + @Override + public EntityPackets1_19_4 getEntityRewriter() { + return entityRewriter; + } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java new file mode 100644 index 00000000..7c15ebde --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/BlockItemPackets1_19_4.java @@ -0,0 +1,101 @@ +/* + * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards + * Copyright (C) 2023 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.protocol1_19_3to1_19_4.packets; + +import com.viaversion.viabackwards.api.rewriters.ItemRewriter; +import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type; +import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3; +import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.rewriter.RecipeRewriter1_19_3; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.rewriter.BlockRewriter; + +public final class BlockItemPackets1_19_4 extends ItemRewriter { + + public BlockItemPackets1_19_4(final Protocol1_19_3To1_19_4 protocol) { + super(protocol); + } + + @Override + public void registerPackets() { + final BlockRewriter blockRewriter = new BlockRewriter<>(protocol, Type.POSITION1_14); + blockRewriter.registerBlockAction(ClientboundPackets1_19_4.BLOCK_ACTION); + blockRewriter.registerBlockChange(ClientboundPackets1_19_4.BLOCK_CHANGE); + blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_19_4.MULTI_BLOCK_CHANGE); + blockRewriter.registerEffect(ClientboundPackets1_19_4.EFFECT, 1010, 2001); + blockRewriter.registerChunkData1_19(ClientboundPackets1_19_4.CHUNK_DATA, Chunk1_18Type::new); + blockRewriter.registerBlockEntityData(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA); + + registerSetCooldown(ClientboundPackets1_19_4.COOLDOWN); + registerWindowItems1_17_1(ClientboundPackets1_19_4.WINDOW_ITEMS); + registerSetSlot1_17_1(ClientboundPackets1_19_4.SET_SLOT); + registerAdvancements(ClientboundPackets1_19_4.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); + registerEntityEquipmentArray(ClientboundPackets1_19_4.ENTITY_EQUIPMENT); + registerClickWindow1_17_1(ServerboundPackets1_19_3.CLICK_WINDOW); + registerTradeList1_19(ClientboundPackets1_19_4.TRADE_LIST); + registerCreativeInvAction(ServerboundPackets1_19_3.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); + registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_4.WINDOW_PROPERTY); + registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE); + + final RecipeRewriter1_19_3 recipeRewriter = new RecipeRewriter1_19_3(protocol) { + @Override + public void handleCraftingShaped(final PacketWrapper wrapper) throws Exception { + final int ingredients = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT); + wrapper.passthrough(Type.STRING); // Group + wrapper.passthrough(Type.VAR_INT); // Crafting book category + for (int i = 0; i < ingredients; i++) { + handleIngredient(wrapper); + } + rewrite(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result + + // Remove notification boolean + wrapper.read(Type.BOOLEAN); + } + }; + protocol.registerClientbound(ClientboundPackets1_19_4.DECLARE_RECIPES, wrapper -> { + final int size = wrapper.passthrough(Type.VAR_INT); + int newSize = size; + for (int i = 0; i < size; i++) { + final String type = wrapper.read(Type.STRING); + final String cutType = type.replace("minecraft:", ""); + if (cutType.equals("smithing_transform") || cutType.equals("smithing_trim")) { + newSize--; + wrapper.read(Type.STRING); // Recipe identifier + wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Template + wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Base + wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Additions + wrapper.read(Type.FLAT_VAR_INT_ITEM); // Result + continue; + } else if (cutType.equals("crafting_decorated_pot")) { + newSize--; + wrapper.read(Type.STRING); // Recipe identifier + wrapper.read(Type.VAR_INT); // Crafting book category + continue; + } + + wrapper.write(Type.STRING, type); + wrapper.passthrough(Type.STRING); // Recipe Identifier + recipeRewriter.handleRecipeType(wrapper, cutType); + } + + wrapper.set(Type.VAR_INT, 0, newSize); + }); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java index 9bf351a5..03fb78ae 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_19_3to1_19_4/packets/EntityPackets1_19_4.java @@ -43,7 +43,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter { + // Source position + if (wrapper.read(Type.BOOLEAN)) { + wrapper.read(Type.DOUBLE); + wrapper.read(Type.DOUBLE); + wrapper.read(Type.DOUBLE); + } + }); + create(Type.BYTE, (byte) 2); // Generic hurt + } + }); + protocol.registerClientbound(ClientboundPackets1_19_4.HIT_ANIMATION, ClientboundPackets1_19_3.ENTITY_ANIMATION, new PacketHandlers() { @Override public void register() { @@ -101,7 +120,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter { int id = meta.metaType().typeId(); - if (id >= 25) { // Vector3f/quaternion types + if (id >= 25) { // Sniffer state, Vector3f, Quaternion types return; } else if (id >= 15) { // Optional block state - just map down to block state id--; @@ -109,7 +128,7 @@ public final class EntityPackets1_19_4 extends EntityRewriter { // Send as custom display name @@ -117,14 +136,21 @@ public final class EntityPackets1_19_4 extends EntityRewriter { + // TODO Maybe spawn an extra entity to ride the armor stand for blocks and items // Remove a large heap of display metadata if (event.index() > 7) { event.cancel(); } }); + filter().type(Entity1_19_4Types.INTERACTION).removeIndex(8); // Width + filter().type(Entity1_19_4Types.INTERACTION).removeIndex(9); // Height + filter().type(Entity1_19_4Types.INTERACTION).removeIndex(10); // Response + + filter().type(Entity1_19_4Types.SNIFFER).removeIndex(17); // State + filter().type(Entity1_19_4Types.SNIFFER).removeIndex(18); // Drop seed at tick + filter().filterFamily(Entity1_19_4Types.ABSTRACT_HORSE).addIndex(18); // Owner UUID } @@ -140,6 +166,10 @@ public final class EntityPackets1_19_4 extends EntityRewriter