From bda4ea9fd09e837914eba4c577c55313a83077aa Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 13 Aug 2024 10:24:07 +0200 Subject: [PATCH] [ci skip] Move template protocol into common module Had to move the rewriter classes into the flattened package to make them package private, but this is nicer than having a separate module just for those --- .../BlockItemPacketRewriter1_99.java | 47 ++++++++--------- .../template}/EntityPacketRewriter1_99.java | 48 ++++++++--------- .../template}/Protocol1_99To_98.java | 52 +++++++++---------- settings.gradle.kts | 1 - template/build.gradle.kts | 3 -- 5 files changed, 71 insertions(+), 80 deletions(-) rename {template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter => common/src/main/java/com/viaversion/viaversion/protocols/template}/BlockItemPacketRewriter1_99.java (57%) rename {template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter => common/src/main/java/com/viaversion/viaversion/protocols/template}/EntityPacketRewriter1_99.java (69%) rename {template/src/main/java/com/viaversion/viaversion/template/protocols => common/src/main/java/com/viaversion/viaversion/protocols/template}/Protocol1_99To_98.java (73%) delete mode 100644 template/build.gradle.kts diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/BlockItemPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java similarity index 57% rename from template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/BlockItemPacketRewriter1_99.java rename to common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java index 2d84d995f..0be808fe5 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/BlockItemPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/BlockItemPacketRewriter1_99.java @@ -15,23 +15,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.template.protocols.rewriter; +package com.viaversion.viaversion.protocols.template; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.StructuredItemRewriter; -import com.viaversion.viaversion.template.protocols.Protocol1_99To_98; // To replace if needed: // ChunkType1_20_2 // RecipeRewriter1_20_3 -public final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter { +final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter { public BlockItemPacketRewriter1_99(final Protocol1_99To_98 protocol) { super(protocol, /*TypesOLD.ITEM, TypesOLD.ITEM_ARRAY, */Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY); @@ -42,31 +41,31 @@ public final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); - blockRewriter.registerBlockEvent(ClientboundPackets1_20_5.BLOCK_EVENT); - blockRewriter.registerBlockUpdate(ClientboundPackets1_20_5.BLOCK_UPDATE); - blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_20_5.SECTION_BLOCKS_UPDATE); - blockRewriter.registerLevelEvent1_21(ClientboundPackets1_20_5.LEVEL_EVENT, 2001); - blockRewriter.registerLevelChunk1_19(ClientboundPackets1_20_5.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); - blockRewriter.registerBlockEntityData(ClientboundPackets1_20_5.BLOCK_ENTITY_DATA); + final BlockRewriter blockRewriter = BlockRewriter.for1_20_2(protocol); + blockRewriter.registerBlockEvent(ClientboundPackets1_21.BLOCK_EVENT); + blockRewriter.registerBlockUpdate(ClientboundPackets1_21.BLOCK_UPDATE); + blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE); + blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21.LEVEL_EVENT, 2001); + blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new); + blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA); // Registers item id changes // Other places using item ids are: Entity data, tags, statistics, effect - // registerOpenWindow(ClientboundPackets1_20_5.OPEN_WINDOW); - If a new container type was added - registerCooldown(ClientboundPackets1_20_5.COOLDOWN); - registerSetContent1_17_1(ClientboundPackets1_20_5.CONTAINER_SET_CONTENT); - registerSetSlot1_17_1(ClientboundPackets1_20_5.CONTAINER_SET_SLOT); - registerAdvancements1_20_3(ClientboundPackets1_20_5.UPDATE_ADVANCEMENTS); - registerSetEquipment(ClientboundPackets1_20_5.SET_EQUIPMENT); + // registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW); - If a new container type was added + registerCooldown(ClientboundPackets1_21.COOLDOWN); + registerSetContent1_17_1(ClientboundPackets1_21.CONTAINER_SET_CONTENT); + registerSetSlot1_17_1(ClientboundPackets1_21.CONTAINER_SET_SLOT); + registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS); + registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT); registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK); - registerMerchantOffers1_20_5(ClientboundPackets1_20_5.MERCHANT_OFFERS, Types1_20_5.ITEM_COST, Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST); + registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS, Types1_20_5.ITEM_COST, Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST); registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT); - registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE); - registerExplosion(ClientboundPackets1_20_5.EXPLODE, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE); // Rewrites the included sound and particles + registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE); + registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE); // Rewrites the included sound and particles - new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_20_5.UPDATE_RECIPES); + new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES); // OR do this if serialization of recipes changed and override the relevant method // Add new serializers to RecipeRewriter, or extend the last one for changes - // new RecipeRewriter1_20_3(this) {}.register1_20_5(ClientboundPackets1_20_5.DECLARE_RECIPES); + // new RecipeRewriter1_20_3(this) {}.register1_20_5(ClientboundPackets1_21.DECLARE_RECIPES); } -} \ No newline at end of file +} diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java b/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java similarity index 69% rename from template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java rename to common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java index b2a097f54..fa887cc74 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/template/EntityPacketRewriter1_99.java @@ -15,25 +15,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.viaversion.viaversion.template.protocols.rewriter; +package com.viaversion.viaversion.protocols.template; import com.viaversion.viaversion.api.minecraft.RegistryEntry; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; -import com.viaversion.viaversion.api.type.types.version.Types1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5; +import com.viaversion.viaversion.api.type.types.version.Types1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.rewriter.EntityRewriter; -import com.viaversion.viaversion.template.protocols.Protocol1_99To_98; import com.viaversion.viaversion.util.Key; // Replace if needed // Types1_OLD -// Types1_20_5 -public final class EntityPacketRewriter1_99 extends EntityRewriter { +// Types1_21 +final class EntityPacketRewriter1_99 extends EntityRewriter { public EntityPacketRewriter1_99(final Protocol1_99To_98 protocol) { super(protocol); @@ -42,17 +41,17 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter { + protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> { final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING)); final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY); handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data }); - protocol.registerClientbound(ClientboundPackets1_20_5.LOGIN, new PacketHandlers() { + protocol.registerClientbound(ClientboundPackets1_21.LOGIN, new PacketHandlers() { @Override public void register() { map(Types.INT); // Entity id @@ -71,7 +70,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter { + protocol.registerClientbound(ClientboundPackets1_21.RESPAWN, wrapper -> { final int dimensionId = wrapper.passthrough(Types.VAR_INT); final String world = wrapper.passthrough(Types.STRING); trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking @@ -82,24 +81,23 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter { - final int id = typeId; + int id = typeId; if (id >= SomeAddedIndex) { id++; } - return Types1_20_5.ENTITY_DATA_TYPES.byId(id); + return Types1_21.ENTITY_DATA_TYPES.byId(id); });*/ // Registers registry type id changes registerEntityDataTypeHandler( - Types1_20_5.ENTITY_DATA_TYPES.itemType, - Types1_20_5.ENTITY_DATA_TYPES.blockStateType, - Types1_20_5.ENTITY_DATA_TYPES.optionalBlockStateType, - Types1_20_5.ENTITY_DATA_TYPES.particleType, - Types1_20_5.ENTITY_DATA_TYPES.particlesType, - Types1_20_5.ENTITY_DATA_TYPES.componentType, - Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType + Types1_21.ENTITY_DATA_TYPES.itemType, + Types1_21.ENTITY_DATA_TYPES.blockStateType, + Types1_21.ENTITY_DATA_TYPES.optionalBlockStateType, + Types1_21.ENTITY_DATA_TYPES.particleType, + Types1_21.ENTITY_DATA_TYPES.particlesType, + Types1_21.ENTITY_DATA_TYPES.componentType, + Types1_21.ENTITY_DATA_TYPES.optionalComponentType ); - // Minecarts are special registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); } @@ -113,4 +111,4 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter. */ -package com.viaversion.viaversion.template.protocols; +package com.viaversion.viaversion.protocols.template; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.MappingData; @@ -25,65 +25,63 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; import com.viaversion.viaversion.data.entity.EntityTrackerBase; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; -import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; import com.viaversion.viaversion.rewriter.AttributeRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; -import com.viaversion.viaversion.template.protocols.rewriter.BlockItemPacketRewriter1_99; -import com.viaversion.viaversion.template.protocols.rewriter.EntityPacketRewriter1_99; import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; // Placeholders to replace (in the entire package): -// Protocol1_99To_98, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99 -// ClientboundPacket1_20_5 +// Protocol1_99To_98, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99 - move the latter two to a rewriter package +// ClientboundPacket1_21 // ServerboundPacket1_20_5 // EntityTypes1_20_5 (MAPPED type) // 1.99, 1.98 -public final class Protocol1_99To_98 extends AbstractProtocol { +final class Protocol1_99To_98 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingDataBase("1.98", "1.99"); private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this); private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this); - private final TagRewriter tagRewriter = new TagRewriter<>(this); + private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_99To_98() { // Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted - super(ClientboundPacket1_20_5.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class); + super(ClientboundPacket1_21.class, ClientboundPacket1_21.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class); } @Override protected void registerPackets() { super.registerPackets(); - tagRewriter.registerGeneric(ClientboundPackets1_20_5.UPDATE_TAGS); - tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundPackets1_21.UPDATE_TAGS); + tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS); - final SoundRewriter soundRewriter = new SoundRewriter<>(this); - soundRewriter.registerSound1_19_3(ClientboundPackets1_20_5.SOUND); - soundRewriter.registerSound1_19_3(ClientboundPackets1_20_5.SOUND_ENTITY); + final SoundRewriter soundRewriter = new SoundRewriter<>(this); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND); + soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY); - new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS); - new AttributeRewriter<>(this).register1_21(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES); + new StatisticsRewriter<>(this).register(ClientboundPackets1_21.AWARD_STATS); + new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21.UPDATE_ATTRIBUTES); // Uncomment if an existing type changed serialization format. Mappings for argument type keys can also be defined in mapping files - /*final CommandRewriter1_19_4 commandRewriter = new CommandRewriter1_19_4(this) { + /*new CommandRewriter1_19_4<>(this) { @Override - public void handleArgument(final PacketWrapper wrapper, final String argumentType) throws Exception { + public void handleArgument(final PacketWrapper wrapper, final String argumentType) { if (argumentType.equals("minecraft:abc")) { // New argument - wrapper.write(Type.INT, 0); + wrapper.write(Types.INT, 0); } else { super.handleArgument(wrapper, argumentType); } } - }.registerDeclareCommands1_19(ClientboundPackets1_20_5.DECLARE_COMMANDS);*/ + }.registerDeclareCommands1_19(ClientboundPackets1_21.COMMANDS);*/ } @Override @@ -130,17 +128,17 @@ public final class Protocol1_99To_98 extends AbstractProtocol getTagRewriter() { + public TagRewriter getTagRewriter() { return tagRewriter; } @Override - protected PacketTypesProvider createPacketTypesProvider() { + protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( - packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class), - packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class), + packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class), packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) ); } -} \ No newline at end of file +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 169cccbc6..5f805ebcc 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,7 +30,6 @@ setupViaSubproject("bukkit") setupViaSubproject("bukkit-legacy") setupViaSubproject("velocity") setupViaSubproject("fabric") -setupViaSubproject("template") setupSubproject("viaversion") { projectDir = file("universal") diff --git a/template/build.gradle.kts b/template/build.gradle.kts deleted file mode 100644 index 67a762997..000000000 --- a/template/build.gradle.kts +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - compileOnly(projects.viaversionCommon) -}