From 6dfd4747ee6e2d8ba04f1f8f4bf31d7ec99b169b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 3 Aug 2023 13:58:22 +1000 Subject: [PATCH] Start working on 23w31a --- .../api/minecraft/metadata/ChunkPosition.java | 73 +++++++++ .../viaversion/api/protocol/packet/State.java | 3 +- .../api/protocol/version/ProtocolVersion.java | 1 + .../viaversion/viaversion/api/type/Type.java | 4 +- .../types/minecraft/ChunkPositionType.java | 45 ++++++ .../protocol/ProtocolManagerImpl.java | 2 + .../base/ServerboundLoginPackets.java | 4 +- .../Protocol1_20_2To1_20.java | 101 ++++++++++++ .../handler/BlockItemPacketHandler1_20_2.java | 65 ++++++++ .../handler/EntityPacketHandler1_20_2.java | 122 +++++++++++++++ ...ClientboundConfigurationPackets1_20_2.java | 49 ++++++ .../packet/ClientboundPackets1_20_2.java | 147 ++++++++++++++++++ ...ServerboundConfigurationPackets1_20_2.java | 45 ++++++ .../packet/ServerboundPackets1_20_2.java | 87 +++++++++++ .../packets/InventoryPackets.java | 6 +- .../viaversion/rewriter/ItemRewriter.java | 37 +++++ gradle.properties | 2 +- 17 files changed, 786 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ChunkPositionType.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/BlockItemPacketHandler1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/EntityPacketHandler1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java create mode 100644 common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java new file mode 100644 index 000000000..7098d676e --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/ChunkPosition.java @@ -0,0 +1,73 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2023 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata; + +import java.util.Objects; + +public final class ChunkPosition { + private final int chunkX; + private final int chunkZ; + + public ChunkPosition(int chunkX, int chunkZ) { + this.chunkX = chunkX; + this.chunkZ = chunkZ; + } + + public ChunkPosition(long chunkKey) { + this.chunkX = (int) chunkKey; + this.chunkZ = (int) (chunkKey >> 32); + } + + public int chunkX() { + return chunkX; + } + + public int chunkZ() { + return chunkZ; + } + + public long chunkKey() { + return (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) << 32; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ChunkPosition that = (ChunkPosition) o; + return chunkX == that.chunkX && chunkZ == that.chunkZ; + } + + @Override + public int hashCode() { + return Objects.hash(chunkX, chunkZ); + } + + @Override + public String toString() { + return "ChunkPosition{" + + "chunkX=" + chunkX + + ", chunkZ=" + chunkZ + + '}'; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/State.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/State.java index fcda6b078..1122c764b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/State.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/packet/State.java @@ -27,5 +27,6 @@ public enum State { HANDSHAKE, STATUS, LOGIN, - PLAY + PLAY, + CONFIGURATION } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java index c61257cb9..a4633672e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java @@ -84,6 +84,7 @@ public class ProtocolVersion { public static final ProtocolVersion v1_19_3 = register(761, "1.19.3"); public static final ProtocolVersion v1_19_4 = register(762, "1.19.4"); public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1)); + public static final ProtocolVersion v1_20_2 = register(764, 144, "1.20.2"); public static final ProtocolVersion unknown = register(-1, "UNKNOWN"); public static ProtocolVersion register(int version, String name) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 2cbfdbcc3..5f415abdb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -36,6 +36,7 @@ import com.viaversion.viaversion.api.minecraft.Vector; import com.viaversion.viaversion.api.minecraft.Vector3f; import com.viaversion.viaversion.api.minecraft.VillagerData; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; import com.viaversion.viaversion.api.type.types.ArrayType; import com.viaversion.viaversion.api.type.types.BooleanType; import com.viaversion.viaversion.api.type.types.ByteArrayType; @@ -59,6 +60,7 @@ import com.viaversion.viaversion.api.type.types.VarIntType; import com.viaversion.viaversion.api.type.types.VarLongType; import com.viaversion.viaversion.api.type.types.VoidType; import com.viaversion.viaversion.api.type.types.minecraft.BlockChangeRecordType; +import com.viaversion.viaversion.api.type.types.minecraft.ChunkPositionType; import com.viaversion.viaversion.api.type.types.minecraft.EulerAngleType; import com.viaversion.viaversion.api.type.types.minecraft.FlatItemArrayType; import com.viaversion.viaversion.api.type.types.minecraft.FlatItemType; @@ -164,9 +166,9 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type QUATERNION = new QuaternionType(); public static final Type NBT = new NBTType(); public static final Type NBT_ARRAY = new ArrayType<>(Type.NBT); - public static final Type GLOBAL_POSITION = new GlobalPositionType(); public static final Type OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType(); + public static final Type CHUNK_POSITION = new ChunkPositionType(); public static final Type BLOCK_CHANGE_RECORD = new BlockChangeRecordType(); public static final Type BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ChunkPositionType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ChunkPositionType.java new file mode 100644 index 000000000..bf5434fea --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ChunkPositionType.java @@ -0,0 +1,45 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2023 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.type.types.minecraft; + +import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; +import com.viaversion.viaversion.api.type.Type; +import io.netty.buffer.ByteBuf; + +public class ChunkPositionType extends Type { + + public ChunkPositionType() { + super(ChunkPosition.class); + } + + @Override + public ChunkPosition read(ByteBuf buffer) throws Exception { + final long chunkKey = Type.LONG.readPrimitive(buffer); + return new ChunkPosition(chunkKey); + } + + @Override + public void write(ByteBuf buffer, ChunkPosition chunkPosition) throws Exception { + Type.LONG.writePrimitive(buffer, chunkPosition.chunkKey()); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java index f0784ae9a..1b1421734 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java @@ -70,6 +70,7 @@ import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.Protocol1_19_3To1_19_1; import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.Protocol1_19_4To1_19_3; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.Protocol1_19To1_18_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20; import com.viaversion.viaversion.protocols.protocol1_20to1_19_4.Protocol1_20To1_19_4; import com.viaversion.viaversion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4; import com.viaversion.viaversion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9; @@ -183,6 +184,7 @@ public class ProtocolManagerImpl implements ProtocolManager { registerProtocol(new Protocol1_19_4To1_19_3(), ProtocolVersion.v1_19_4, ProtocolVersion.v1_19_3); registerProtocol(new Protocol1_20To1_19_4(), ProtocolVersion.v1_20, ProtocolVersion.v1_19_4); + registerProtocol(new Protocol1_20_2To1_20(), ProtocolVersion.v1_20_2, ProtocolVersion.v1_20); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/base/ServerboundLoginPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/base/ServerboundLoginPackets.java index d7e4bee0b..f0cfaed24 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/base/ServerboundLoginPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/base/ServerboundLoginPackets.java @@ -23,7 +23,9 @@ import com.viaversion.viaversion.api.protocol.packet.State; public enum ServerboundLoginPackets implements ServerboundPacketType { HELLO, // 0x00 ENCRYPTION_KEY, // 0x01 - CUSTOM_QUERY; // 0x02 + CUSTOM_QUERY, // 0x02 + CUSTOM_QUERY_ANSWER, // 0x03 + LOGIN_ACKNOWLEDGED; // 0x04 @Override public final int getId() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java new file mode 100644 index 000000000..12518da56 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/Protocol1_20_2To1_20.java @@ -0,0 +1,101 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * 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.viaversion.protocols.protocol1_20_2to1_20; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; +import com.viaversion.viaversion.api.protocol.AbstractProtocol; +import com.viaversion.viaversion.api.protocol.packet.State; +import com.viaversion.viaversion.api.rewriter.EntityRewriter; +import com.viaversion.viaversion.api.rewriter.ItemRewriter; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.data.entity.EntityTrackerBase; +import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.handler.BlockItemPacketHandler1_20_2; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.handler.EntityPacketHandler1_20_2; +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.rewriter.SoundRewriter; +import com.viaversion.viaversion.rewriter.StatisticsRewriter; +import com.viaversion.viaversion.rewriter.TagRewriter; + +import java.util.UUID; + +public final class Protocol1_20_2To1_20 extends AbstractProtocol { + + private final EntityPacketHandler1_20_2 entityPacketHandler = new EntityPacketHandler1_20_2(this); + private final BlockItemPacketHandler1_20_2 itemPacketHandler = new BlockItemPacketHandler1_20_2(this); + + public Protocol1_20_2To1_20() { + // Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted + super(ClientboundPackets1_19_4.class, ClientboundPackets1_20_2.class, ServerboundPackets1_19_4.class, ServerboundPackets1_20_2.class); + } + + @Override + protected void registerPackets() { + // TODO Stopped at ForgetLevelChunk + // TODO New login packets (custom query answer, login ack) + // TODO Handle move from and to configuration state + // Game profile/serverbound ack -> configuration + // Client/serverbound config finish -> play + // TODO New helper methods for: join game, respawn, + // TODO Make sure Paper/Velocity handle a 0,0 uuid fine during login + + // Lesser: + // TODO Player info, replace profile with missing name with null? + // TODO Scoreboard objective probably okay, but there are refactors to the id + super.registerPackets(); + + final TagRewriter tagRewriter = new TagRewriter<>(this); + tagRewriter.registerGeneric(ClientboundPackets1_19_4.TAGS); + + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.register1_19_3Sound(ClientboundPackets1_19_4.SOUND); + soundRewriter.registerSound(ClientboundPackets1_19_4.ENTITY_SOUND); + + new StatisticsRewriter<>(this).register(ClientboundPackets1_19_4.STATISTICS); + + registerClientbound(ClientboundPackets1_19_4.SCOREBOARD_OBJECTIVE, wrapper -> { + final byte slot = wrapper.read(Type.BYTE); + wrapper.write(Type.VAR_INT, (int) slot); + }); + + registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO.getId(), ClientboundLoginPackets.HELLO.getId(), wrapper -> { + wrapper.passthrough(Type.STRING); // Name + final UUID uuid = wrapper.read(Type.OPTIONAL_UUID); + wrapper.write(Type.UUID, uuid != null ? uuid : new UUID(0, 0)); + }); + } + + @Override + public void init(final UserConnection user) { + addEntityTracker(user, new EntityTrackerBase(user, Entity1_19_4Types.PLAYER)); + } + + @Override + public EntityRewriter getEntityRewriter() { + return entityPacketHandler; + } + + @Override + public ItemRewriter getItemRewriter() { + return itemPacketHandler; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/BlockItemPacketHandler1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/BlockItemPacketHandler1_20_2.java new file mode 100644 index 000000000..8c760e223 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/BlockItemPacketHandler1_20_2.java @@ -0,0 +1,65 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * 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.viaversion.protocols.protocol1_20_2to1_20.handler; + +import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition; +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_4to1_19_3.ClientboundPackets1_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.Protocol1_20_2To1_20; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.packet.ServerboundPackets1_20_2; +import com.viaversion.viaversion.rewriter.BlockRewriter; +import com.viaversion.viaversion.rewriter.ItemRewriter; + +public final class BlockItemPacketHandler1_20_2 extends ItemRewriter { + + public BlockItemPacketHandler1_20_2(final Protocol1_20_2To1_20 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.registerVarLongMultiBlockChange1_20(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); + registerAdvancements1_20(ClientboundPackets1_19_4.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM); + registerEntityEquipmentArray(ClientboundPackets1_19_4.ENTITY_EQUIPMENT); + registerClickWindow1_17_1(ServerboundPackets1_20_2.CLICK_WINDOW); + registerTradeList1_19(ClientboundPackets1_19_4.TRADE_LIST); + registerCreativeInvAction(ServerboundPackets1_20_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); + registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_4.WINDOW_PROPERTY); + registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE); + + new RecipeRewriter1_19_4<>(protocol).register(ClientboundPackets1_19_4.DECLARE_RECIPES); + + protocol.registerClientbound(ClientboundPackets1_19_4.UNLOAD_CHUNK, wrapper -> { + final int x = wrapper.read(Type.INT); + final int z = wrapper.read(Type.INT); + wrapper.write(Type.CHUNK_POSITION, new ChunkPosition(x, z)); + }); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/EntityPacketHandler1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/EntityPacketHandler1_20_2.java new file mode 100644 index 000000000..f5dc6e47b --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/handler/EntityPacketHandler1_20_2.java @@ -0,0 +1,122 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * 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.viaversion.protocols.protocol1_20_2to1_20.handler; + +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.version.Types1_20; +import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4; +import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.Protocol1_20_2To1_20; +import com.viaversion.viaversion.rewriter.EntityRewriter; + +public final class EntityPacketHandler1_20_2 extends EntityRewriter { + + public EntityPacketHandler1_20_2(final Protocol1_20_2To1_20 protocol) { + super(protocol); + } + + @Override + public void registerPackets() { + registerTrackerWithData1_19(ClientboundPackets1_19_4.SPAWN_ENTITY, Entity1_19_4Types.FALLING_BLOCK); + registerMetadataRewriter(ClientboundPackets1_19_4.ENTITY_METADATA, Types1_20.METADATA_LIST); + registerRemoveEntities(ClientboundPackets1_19_4.REMOVE_ENTITIES); + + protocol.registerClientbound(ClientboundPackets1_19_4.JOIN_GAME, new PacketHandlers() { + @Override + public void register() { + handler(wrapper -> { + // Just reorder written data, move dimension data to configuration phase + wrapper.passthrough(Type.INT); // Entity id + wrapper.passthrough(Type.BOOLEAN); // Hardcore + + final byte gamemode = wrapper.read(Type.UNSIGNED_BYTE).byteValue(); + final byte previousGamemode = wrapper.read(Type.BYTE); + + wrapper.passthrough(Type.STRING_ARRAY); // World List + + final CompoundTag dimensionRegistry = wrapper.read(Type.NBT); // TODO AAAAAAAAAAAAAAAAAAAAA + final String dimensionType = wrapper.read(Type.STRING); + final String world = wrapper.read(Type.STRING); + final long seed = wrapper.read(Type.LONG); + + wrapper.passthrough(Type.VAR_INT); // Max players + wrapper.passthrough(Type.VAR_INT); // View distance + wrapper.passthrough(Type.VAR_INT); // Simulation distance + wrapper.passthrough(Type.BOOLEAN); // Reduced debug info + wrapper.passthrough(Type.BOOLEAN); // Show death screen + + wrapper.write(Type.STRING, dimensionType); + wrapper.write(Type.STRING, world); + wrapper.write(Type.LONG, seed); + wrapper.write(Type.BYTE, gamemode); + wrapper.write(Type.BYTE, previousGamemode); + + wrapper.passthrough(Type.BOOLEAN); // Debug + wrapper.passthrough(Type.BOOLEAN); // Flat + wrapper.passthrough(Type.OPTIONAL_GLOBAL_POSITION); // Last death position + wrapper.passthrough(Type.VAR_INT); // Portal cooldown + }); + handler(dimensionDataHandler()); // Caches dimensions to access data like height later + handler(biomeSizeTracker()); // Tracks the amount of biomes sent for chunk data + handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking + } + }); + + protocol.registerClientbound(ClientboundPackets1_19_4.RESPAWN, new PacketHandlers() { + @Override + public void register() { + handler(wrapper -> { + wrapper.passthrough(Type.STRING); // Dimension type + wrapper.passthrough(Type.STRING); // World + wrapper.passthrough(Type.LONG); // Seed + wrapper.passthrough(Type.BYTE); // Gamemode + wrapper.passthrough(Type.BYTE); // Previous gamemode + wrapper.passthrough(Type.BOOLEAN); // Debug + wrapper.passthrough(Type.BOOLEAN); // Flat + + // Move this to the end + final byte dataToKeep = wrapper.read(Type.BYTE); + + wrapper.passthrough(Type.OPTIONAL_GLOBAL_POSITION); // Last death position + wrapper.passthrough(Type.VAR_INT); // Portal cooldown + + wrapper.write(Type.BYTE, dataToKeep); + }); + handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking + } + }); + } + + @Override + protected void registerRewrites() { + registerMetaTypeHandler(Types1_20.META_TYPES.itemType, Types1_20.META_TYPES.blockStateType, Types1_20.META_TYPES.optionalBlockStateType, Types1_20.META_TYPES.particleType); + + filter().filterFamily(Entity1_19_4Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> { + final int blockState = meta.value(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); + }); + } + + @Override + public EntityType typeFromId(final int type) { + return Entity1_19_4Types.getTypeFromId(type); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java new file mode 100644 index 000000000..1ca1be5f9 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundConfigurationPackets1_20_2.java @@ -0,0 +1,49 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-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.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; +import com.viaversion.viaversion.api.protocol.packet.State; + +public enum ClientboundConfigurationPackets1_20_2 implements ClientboundPacketType { + + CUSTOM_PAYLOAD, // 0x00 + DISCONNECT, // 0x01 + FINISH_CONFIGURATION, // 0x02 + KEEP_ALIVE, // 0x03 + PING, // 0x04 + REGISTRY_DATA, // 0x05 + RESOURCE_PACK, // 0x06 + UPDATE_ENABLED_FEATURES, // 0x07 + UPDATE_TAGS; // 0x08 + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } + + @Override + public State state() { + return State.CONFIGURATION; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java new file mode 100644 index 000000000..157d16725 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ClientboundPackets1_20_2.java @@ -0,0 +1,147 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-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.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; + +public enum ClientboundPackets1_20_2 implements ClientboundPacketType { + + BUNDLE, // 0x00 + SPAWN_ENTITY, // 0x01 + SPAWN_EXPERIENCE_ORB, // 0x02 + SPAWN_PLAYER, // 0x03 + ENTITY_ANIMATION, // 0x04 + STATISTICS, // 0x05 + BLOCK_CHANGED_ACK, // 0x06 + BLOCK_BREAK_ANIMATION, // 0x07 + BLOCK_ENTITY_DATA, // 0x08 + BLOCK_ACTION, // 0x09 + BLOCK_CHANGE, // 0x0A + BOSSBAR, // 0x0B + SERVER_DIFFICULTY, // 0x0C + CHUNK_BATCH_FINISHED, // 0x0D // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + CHUNK_BATCH_START, // 0x0E // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + CHUNK_BIOMES, // 0x0F + CLEAR_TITLES, // 0x10 + TAB_COMPLETE, // 0x11 + DECLARE_COMMANDS, // 0x12 + CLOSE_WINDOW, // 0x13 + WINDOW_ITEMS, // 0x14 + WINDOW_PROPERTY, // 0x15 + SET_SLOT, // 0x16 + COOLDOWN, // 0x17 + CUSTOM_CHAT_COMPLETIONS, // 0x18 + PLUGIN_MESSAGE, // 0x19 // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + DAMAGE_EVENT, // 0x1A + DELETE_CHAT_MESSAGE, // 0x1B + DISCONNECT, // 0x1C + DISGUISED_CHAT, // 0x1D + ENTITY_STATUS, // 0x1E + EXPLOSION, // 0x1F + UNLOAD_CHUNK, // 0x20 + GAME_EVENT, // 0x21 + OPEN_HORSE_WINDOW, // 0x22 + HIT_ANIMATION, // 0x23 + WORLD_BORDER_INIT, // 0x24 + KEEP_ALIVE, // 0x25 + CHUNK_DATA, // 0x26 + EFFECT, // 0x27 + SPAWN_PARTICLE, // 0x28 + UPDATE_LIGHT, // 0x29 + JOIN_GAME, // 0x2A + MAP_DATA, // 0x2B + TRADE_LIST, // 0x2C + ENTITY_POSITION, // 0x2D + ENTITY_POSITION_AND_ROTATION, // 0x2E + ENTITY_ROTATION, // 0x2F + VEHICLE_MOVE, // 0x30 + OPEN_BOOK, // 0x31 + OPEN_WINDOW, // 0x32 + OPEN_SIGN_EDITOR, // 0x33 + PING, // 0x34 + CRAFT_RECIPE_RESPONSE, // 0x35 + PLAYER_ABILITIES, // 0x36 + PLAYER_CHAT, // 0x37 + COMBAT_END, // 0x38 + COMBAT_ENTER, // 0x39 + COMBAT_KILL, // 0x3A + PLAYER_INFO_REMOVE, // 0x3B + PLAYER_INFO_UPDATE, // 0x3C + FACE_PLAYER, // 0x3D + PLAYER_POSITION, // 0x3E + UNLOCK_RECIPES, // 0x3F + REMOVE_ENTITIES, // 0x40 + REMOVE_ENTITY_EFFECT, // 0x41 + RESOURCE_PACK, // 0x42 + RESPAWN, // 0x43 + ENTITY_HEAD_LOOK, // 0x44 + MULTI_BLOCK_CHANGE, // 0x45 + SELECT_ADVANCEMENTS_TAB, // 0x46 + SERVER_DATA, // 0x47 + ACTIONBAR, // 0x48 + WORLD_BORDER_CENTER, // 0x49 + WORLD_BORDER_LERP_SIZE, // 0x4A + WORLD_BORDER_SIZE, // 0x4B + WORLD_BORDER_WARNING_DELAY, // 0x4C + WORLD_BORDER_WARNING_DISTANCE, // 0x4D + CAMERA, // 0x4E + HELD_ITEM_CHANGE, // 0x4F + UPDATE_VIEW_POSITION, // 0x50 + UPDATE_VIEW_DISTANCE, // 0x51 + SPAWN_POSITION, // 0x52 + DISPLAY_SCOREBOARD, // 0x53 + ENTITY_METADATA, // 0x54 + ATTACH_ENTITY, // 0x55 + ENTITY_VELOCITY, // 0x56 + ENTITY_EQUIPMENT, // 0x57 + SET_EXPERIENCE, // 0x58 + UPDATE_HEALTH, // 0x59 + SCOREBOARD_OBJECTIVE, // 0x5A + SET_PASSENGERS, // 0x5B + TEAMS, // 0x5C + UPDATE_SCORE, // 0x5D + SET_SIMULATION_DISTANCE, // 0x5E + TITLE_SUBTITLE, // 0x5F + TIME_UPDATE, // 0x60 + TITLE_TEXT, // 0x61 + TITLE_TIMES, // 0x62 + ENTITY_SOUND, // 0x63 + SOUND, // 0x64 + START_CONFIGURATION, // 0x65 // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + STOP_SOUND, // 0x66 + SYSTEM_CHAT, // 0x67 + TAB_LIST, // 0x68 + NBT_QUERY, // 0x69 + COLLECT_ITEM, // 0x6A + ENTITY_TELEPORT, // 0x6B + ADVANCEMENTS, // 0x6C + ENTITY_PROPERTIES, // 0x6D + ENTITY_EFFECT, // 0x6E + DECLARE_RECIPES, // 0x6F + TAGS; // 0x70 + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java new file mode 100644 index 000000000..7db54a189 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundConfigurationPackets1_20_2.java @@ -0,0 +1,45 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-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.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; +import com.viaversion.viaversion.api.protocol.packet.State; + +public enum ServerboundConfigurationPackets1_20_2 implements ServerboundPacketType { + + CUSTOM_PAYLOAD, // 0x00 + FINISH_CONFIGURATION, // 0x01 + KEEP_ALIVE, // 0x02 + PONG, // 0x03 + RESOURCE_PACK; // 0x04 + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } + + @Override + public State state() { + return State.CONFIGURATION; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java new file mode 100644 index 000000000..be5f8a946 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_2to1_20/packet/ServerboundPackets1_20_2.java @@ -0,0 +1,87 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-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.viaversion.protocols.protocol1_20_2to1_20.packet; + +import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; + +public enum ServerboundPackets1_20_2 implements ServerboundPacketType { + + TELEPORT_CONFIRM, // 0x00 + QUERY_BLOCK_NBT, // 0x01 + SET_DIFFICULTY, // 0x02 + CHAT_ACK, // 0x03 + CHAT_COMMAND, // 0x04 + CHAT_MESSAGE, // 0x05 + CHAT_SESSION_UPDATE, // 0x06 + CHUNK_BATCH_RECEIVED, // 0x07 // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + CLIENT_STATUS, // 0x08 + CLIENT_SETTINGS, // 0x09 + TAB_COMPLETE, // 0x0A + CONFIGURATION_ACKNOWLEDGED, // 0x0B // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + CLICK_WINDOW_BUTTON, // 0x0C + CLICK_WINDOW, // 0x0D + CLOSE_WINDOW, // 0x0E + PLUGIN_MESSAGE, // 0x0F // TODO AAAAAAAAAAAAAAAAAAAAAAAAA + EDIT_BOOK, // 0x10 + ENTITY_NBT_REQUEST, // 0x11 + INTERACT_ENTITY, // 0x12 + GENERATE_JIGSAW, // 0x13 + KEEP_ALIVE, // 0x14 + LOCK_DIFFICULTY, // 0x15 + PLAYER_POSITION, // 0x16 + PLAYER_POSITION_AND_ROTATION, // 0x17 + PLAYER_ROTATION, // 0x18 + PLAYER_MOVEMENT, // 0x19 + VEHICLE_MOVE, // 0x1A + STEER_BOAT, // 0x1B + PICK_ITEM, // 0x1C + CRAFT_RECIPE_REQUEST, // 0x1D + PLAYER_ABILITIES, // 0x1E + PLAYER_DIGGING, // 0x1F + ENTITY_ACTION, // 0x20 + STEER_VEHICLE, // 0x21 + PONG, // 0x22 + RECIPE_BOOK_DATA, // 0x23 + SEEN_RECIPE, // 0x24 + RENAME_ITEM, // 0x25 + RESOURCE_PACK_STATUS, // 0x26 + ADVANCEMENT_TAB, // 0x27 + SELECT_TRADE, // 0x28 + SET_BEACON_EFFECT, // 0x29 + HELD_ITEM_CHANGE, // 0x2A + UPDATE_COMMAND_BLOCK, // 0x2B + UPDATE_COMMAND_BLOCK_MINECART, // 0x2C + CREATIVE_INVENTORY_ACTION, // 0x2D + UPDATE_JIGSAW_BLOCK, // 0x2E + UPDATE_STRUCTURE_BLOCK, // 0x2F + UPDATE_SIGN, // 0x30 + ANIMATION, // 0x31 + SPECTATE, // 0x32 + PLAYER_BLOCK_PLACEMENT, // 0x33 + USE_ITEM; // 0x34 + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/InventoryPackets.java index 644927ecb..4e447608d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20to1_19_4/packets/InventoryPackets.java @@ -67,9 +67,9 @@ public final class InventoryPackets extends ItemRewriter type) { + protocol.registerClientbound(packetType, wrapper -> { + wrapper.passthrough(Type.BOOLEAN); // Reset/clear + int size = wrapper.passthrough(Type.VAR_INT); // Mapping size + for (int i = 0; i < size; i++) { + wrapper.passthrough(Type.STRING); // Identifier + + // Parent + if (wrapper.passthrough(Type.BOOLEAN)) + wrapper.passthrough(Type.STRING); + + // Display data + if (wrapper.passthrough(Type.BOOLEAN)) { + wrapper.passthrough(Type.COMPONENT); // Title + wrapper.passthrough(Type.COMPONENT); // Description + handleItemToClient(wrapper.passthrough(type)); // Icon + wrapper.passthrough(Type.VAR_INT); // Frame type + int flags = wrapper.passthrough(Type.INT); // Flags + if ((flags & 1) != 0) { + wrapper.passthrough(Type.STRING); // Background texture + } + wrapper.passthrough(Type.FLOAT); // X + wrapper.passthrough(Type.FLOAT); // Y + } + + wrapper.passthrough(Type.STRING_ARRAY); // Criteria + + int arrayLength = wrapper.passthrough(Type.VAR_INT); + for (int array = 0; array < arrayLength; array++) { + wrapper.passthrough(Type.STRING_ARRAY); // String array + } + + wrapper.passthrough(Type.BOOLEAN); // Send telemetry + } + }); + } + public void registerWindowPropertyEnchantmentHandler(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override diff --git a/gradle.properties b/gradle.properties index 514c236ad..99b71aa40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project properties - we put these here so they can be modified without causing a recompile of the build scripts -projectVersion=4.7.1-SNAPSHOT +projectVersion=4.8.0-23w31a-SNAPSHOT # Gradle properties org.gradle.daemon=true