From 406733b13af8d61af92079e829371dc9138d109f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 10 Aug 2023 16:55:03 +1000 Subject: [PATCH] 23w32a --- build.gradle.kts | 2 +- .../api/ViaBackwardsPlatform.java | 2 +- .../Protocol1_20To1_20_2.java | 12 ++- .../BlockItemPacketRewriter1_20_2.java | 89 ++++++++++++++++++- .../rewriter/EntityPacketRewriter1_20_2.java | 15 +++- .../storage/ConfigurationPacketStorage.java | 4 +- gradle/libs.versions.toml | 2 +- 7 files changed, 107 insertions(+), 19 deletions(-) rename common/src/main/java/com/viaversion/viabackwards/protocol/{protocol1_20_4to1_20_2 => protocol1_20to1_20_2}/Protocol1_20To1_20_2.java (94%) rename common/src/main/java/com/viaversion/viabackwards/protocol/{protocol1_20_4to1_20_2 => protocol1_20to1_20_2}/rewriter/BlockItemPacketRewriter1_20_2.java (81%) rename common/src/main/java/com/viaversion/viabackwards/protocol/{protocol1_20_4to1_20_2 => protocol1_20to1_20_2}/rewriter/EntityPacketRewriter1_20_2.java (89%) rename common/src/main/java/com/viaversion/viabackwards/protocol/{protocol1_20_4to1_20_2 => protocol1_20to1_20_2}/storage/ConfigurationPacketStorage.java (95%) diff --git a/build.gradle.kts b/build.gradle.kts index 803e50bf..583ad5e3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.8.0-23w31a-SNAPSHOT" + version = "4.8.0-23w32a-SNAPSHOT" description = "Allow older clients to join newer server versions." } 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 f94ef6d8..6e1f988e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsPlatform.java @@ -51,7 +51,7 @@ import com.viaversion.viabackwards.protocol.protocol1_19_1to1_19_3.Protocol1_19_ import com.viaversion.viabackwards.protocol.protocol1_19_3to1_19_4.Protocol1_19_3To1_19_4; import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20; import com.viaversion.viabackwards.protocol.protocol1_19to1_19_1.Protocol1_19To1_19_1; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.Protocol1_20To1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2; import com.viaversion.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.protocol.ProtocolManager; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/Protocol1_20To1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java similarity index 94% rename from common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/Protocol1_20To1_20_2.java rename to common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java index 3784ecd8..1c28a790 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/Protocol1_20To1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/Protocol1_20To1_20_2.java @@ -15,13 +15,12 @@ * 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_20_4to1_20_2; +package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2; import com.viaversion.viabackwards.api.BackwardsProtocol; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.rewriter.BlockItemPacketRewriter1_20_2; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.rewriter.EntityPacketRewriter1_20_2; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.storage.ConfigurationPacketStorage; -import com.viaversion.viaversion.api.Via; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter.BlockItemPacketRewriter1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter.EntityPacketRewriter1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.storage.ConfigurationPacketStorage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; import com.viaversion.viaversion.api.protocol.packet.Direction; @@ -55,7 +54,6 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol { final int slot = wrapper.read(Type.VAR_INT); @@ -73,7 +71,6 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol { wrapper.cancel(); wrapper.create(ServerboundConfigurationPackets1_20_2.FINISH_CONFIGURATION).sendToServer(Protocol1_20To1_20_2.class); - wrapper.user().getProtocolInfo().setState(State.PLAY); wrapper.user().get(ConfigurationPacketStorage.class).setFinished(true); }); @@ -86,6 +83,7 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol. */ -package com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.rewriter; +package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter; import com.viaversion.viabackwards.api.rewriters.ItemRewriter; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.Protocol1_20To1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2; import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.entity.EntityTracker; +import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; 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.libs.fastutil.objects.Object2IntMap; +import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap; +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_18to1_17_1.types.Chunk1_18Type; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; -import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.rewriter.RecipeRewriter1_19_4; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ClientboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.RecipeRewriter1_20_2; import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.type.ChunkType1_20_2; import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; +import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.MathUtil; +import java.util.Arrays; +import java.util.List; +import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { + private final Object2IntMap effects = new Object2IntOpenHashMap<>(); + public BlockItemPacketRewriter1_20_2(final Protocol1_20To1_20_2 protocol) { super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_VAR_INT_ARRAY); + + final List effects = Arrays.asList( + "speed", + "slowness", + "haste", + "mining_fatigue", + "strength", + "instant_health", + "instant_damage", + "jump_boost", + "nausea", + "regeneration", + "resistance", + "fire_resistance", + "water_breathing", + "invisibility", + "blindness", + "night_vision", + "hunger", + "weakness", + "poison", + "wither", + "health_boost", + "absorption", + "saturation", + "glowing", + "levitation", + "luck", + "unluck", + "slow_falling", + "conduit_power", + "dolphins_grace", + "bad_omen", + "hero_of_the_village", + "darkness" + ); + for (int i = 0; i < effects.size(); i++) { + final String effect = effects.get(i); + this.effects.put(effect, i + 1); // Effects start at 1 before 1.20.2 + } } @Override @@ -68,7 +119,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { wrapper.passthrough(Type.POSITION1_14); // Position wrapper.passthrough(Type.VAR_INT); // Type - wrapper.write(Type.NBT, wrapper.read(Type.NAMELESS_NBT)); + wrapper.write(Type.NBT, handleBlockEntity(wrapper.read(Type.NAMELESS_NBT))); }); protocol.registerClientbound(ClientboundPackets1_20_2.CHUNK_DATA, wrapper -> { @@ -82,6 +133,17 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter { + if (wrapper.passthrough(Type.BOOLEAN)) { + // Effects start at 1 before 1.20.2 + wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) - 1); + } }); // Replace the NBT type everywhere @@ -305,4 +367,23 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter. */ -package com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.rewriter; +package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter; import com.viaversion.viabackwards.api.rewriters.EntityRewriter; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.Protocol1_20To1_20_2; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.storage.ConfigurationPacketStorage; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.storage.ConfigurationPacketStorage; import com.viaversion.viaversion.api.minecraft.GlobalPosition; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; @@ -43,6 +43,15 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter { + wrapper.passthrough(Type.VAR_INT); // Entity id + wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) + 1); // Effect id + }); + protocol.registerClientbound(ClientboundPackets1_20_2.ENTITY_EFFECT, wrapper -> { + wrapper.passthrough(Type.VAR_INT); // Entity id + wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT) + 1); // Effect id + }); + protocol.registerClientbound(ClientboundPackets1_20_2.JOIN_GAME, new PacketHandlers() { @Override public void register() { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/storage/ConfigurationPacketStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/storage/ConfigurationPacketStorage.java similarity index 95% rename from common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/storage/ConfigurationPacketStorage.java rename to common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/storage/ConfigurationPacketStorage.java index 40cb1e2e..ffb6342a 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20_4to1_20_2/storage/ConfigurationPacketStorage.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_20to1_20_2/storage/ConfigurationPacketStorage.java @@ -15,10 +15,10 @@ * 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_20_4to1_20_2.storage; +package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.storage; import com.google.common.base.Preconditions; -import com.viaversion.viabackwards.protocol.protocol1_20_4to1_20_2.Protocol1_20To1_20_2; +import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2; import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketType; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d03f12e5..07b06060 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ metadata.format.version = "1.1" [versions] # ViaVersion -viaver = "4.8.0-23w31a-SNAPSHOT" +viaver = "4.8.0-23w32a-SNAPSHOT" # Common provided netty = "4.0.20.Final"