From 717b711ad876af7c81cc715b4f9fd88675efdef2 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 13 Jan 2024 06:54:20 +0100 Subject: [PATCH 1/3] Updated VV API usage --- .../MetadataRewriter1_16to20w14infinite.java | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/metadata/MetadataRewriter1_16to20w14infinite.java b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/metadata/MetadataRewriter1_16to20w14infinite.java index 225fac1..3b61948 100644 --- a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/metadata/MetadataRewriter1_16to20w14infinite.java +++ b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/metadata/MetadataRewriter1_16to20w14infinite.java @@ -17,18 +17,13 @@ */ package net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.metadata; -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16; -import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.rewriter.EntityRewriter; import net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.ClientboundPackets20w14infinite; import net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.Protocol1_16to20w14infinite; -import java.util.List; - public class MetadataRewriter1_16to20w14infinite extends EntityRewriter { public MetadataRewriter1_16to20w14infinite(Protocol1_16to20w14infinite protocol) { @@ -38,37 +33,21 @@ public MetadataRewriter1_16to20w14infinite(Protocol1_16to20w14infinite protocol) } @Override - public EntityType typeFromId(int type) { - return EntityTypes1_16.getTypeFromId(type); - } - - @Override - public void handleMetadata(int entityId, EntityType type, Metadata metadata, List metadatas, UserConnection connection) { - if (metadata.metaType() == Types1_14.META_TYPES.itemType) { - metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(metadata.value())); - } else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) { - int data = (int) metadata.getValue(); - metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == Types1_14.META_TYPES.particleType) { - rewriteParticle((Particle) metadata.getValue()); - } + protected void registerRewrites() { + registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, null, Types1_14.META_TYPES.particleType); - if (type == null) return; - - if (type.isOrHasParent(EntityTypes1_16.MINECART_ABSTRACT) - && metadata.id() == 10) { + filter().type(EntityTypes1_16.MINECART_ABSTRACT).index(10).handler((event, meta) -> { // Convert to new block id - int data = (int) metadata.getValue(); - metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } + int data = (int) meta.getValue(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + + filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8); + } - if (type.isOrHasParent(EntityTypes1_16.ABSTRACT_ARROW)) { - if (metadata.id() == 8) { - metadatas.remove(metadata); - } else if (metadata.id() > 8) { - metadata.setId(metadata.id() - 1); - } - } + @Override + public EntityType typeFromId(int type) { + return EntityTypes1_16.getTypeFromId(type); } } From 7ec2b0ac635cf59c5f88bdccd8db46cad722d2c6 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 13 Jan 2024 08:37:36 +0100 Subject: [PATCH 2/3] Optimized mapping loading --- .../Protocol1_14to3D_Shareware.java | 8 +++----- .../Protocol1_16to20w14infinite.java | 18 +++++------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_14to3D_Shareware/Protocol1_14to3D_Shareware.java b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_14to3D_Shareware/Protocol1_14to3D_Shareware.java index decafb7..43bca2f 100644 --- a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_14to3D_Shareware/Protocol1_14to3D_Shareware.java +++ b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_14to3D_Shareware/Protocol1_14to3D_Shareware.java @@ -34,10 +34,10 @@ public class Protocol1_14to3D_Shareware extends BackwardsProtocol { - public static final BackwardsMappings MAPPINGS = new BackwardsMappings("3D_Shareware", "1.14"); + public static final BackwardsMappings MAPPINGS = new BackwardsMappings("3D_Shareware", "1.14", Protocol1_14To1_13_2.class); private static final int SERVERSIDE_VIEW_DISTANCE = 64; - private BlockItemPackets3D_Shareware blockItemPackets; + private final BlockItemPackets3D_Shareware blockItemPackets = new BlockItemPackets3D_Shareware(this); public Protocol1_14to3D_Shareware() { super(ClientboundPackets3D_Shareware.class, ClientboundPackets1_14.class, ServerboundPackets3D_Shareware.class, ServerboundPackets1_14.class); @@ -45,10 +45,8 @@ public Protocol1_14to3D_Shareware() { @Override protected void registerPackets() { - executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::load); + super.registerPackets(); - this.blockItemPackets = new BlockItemPackets3D_Shareware(this); - this.blockItemPackets.register(); new EntityPackets3D_Shareware(this).registerPackets(); final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound(ClientboundPackets3D_Shareware.SOUND); diff --git a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java index e457d0d..06eb2aa 100644 --- a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java +++ b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java @@ -42,12 +42,12 @@ public class Protocol1_16to20w14infinite extends BackwardsProtocol { - public static final BackwardsMappings MAPPINGS = new BackwardsMappings("20w14infinite", "1.16"); + public static final BackwardsMappings MAPPINGS = new BackwardsMappings("20w14infinite", "1.16", Protocol1_16To1_15_2.class); private static final UUID ZERO_UUID = new UUID(0, 0); - private BlockItemPackets20w14infinite blockItemPackets; + private final BlockItemPackets20w14infinite blockItemPackets = new BlockItemPackets20w14infinite(this); + private final MetadataRewriter1_16to20w14infinite metadataRewriter = new MetadataRewriter1_16to20w14infinite(this); private TagRewriter tagRewriter; - private MetadataRewriter1_16to20w14infinite metadataRewriter; public Protocol1_16to20w14infinite() { super(ClientboundPackets20w14infinite.class, ClientboundPackets1_16.class, ServerboundPackets20w14infinite.class, ServerboundPackets1_16.class); @@ -55,19 +55,11 @@ public Protocol1_16to20w14infinite() { @Override protected void registerPackets() { - this.metadataRewriter = new MetadataRewriter1_16to20w14infinite(this); - metadataRewriter.register(); - tagRewriter = new TagRewriter<>(this); - - this.executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, () -> { - MAPPINGS.load(); - this.onMappingDataLoaded(); - }); + super.registerPackets(); + tagRewriter = new TagRewriter<>(this); tagRewriter.register(ClientboundPackets20w14infinite.TAGS, RegistryType.ENTITY); new StatisticsRewriter<>(this).register(ClientboundPackets20w14infinite.STATISTICS); - this.blockItemPackets = new BlockItemPackets20w14infinite(this); - this.blockItemPackets.register(); EntityPackets20w14infinite.register(this); final SoundRewriter soundRewriter = new SoundRewriter<>(this); soundRewriter.registerSound(ClientboundPackets20w14infinite.SOUND); From 3d9feb2d812ae039bcfabdb305e943a049e267cd Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 13 Jan 2024 08:44:08 +0100 Subject: [PATCH 3/3] Ensure TagRewriter is initialized after mapping loading --- .../Protocol1_16to20w14infinite.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java index 06eb2aa..a7223ed 100644 --- a/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java +++ b/src/main/java/net/raphimc/viaaprilfools/protocols/protocol1_16to20w14infinite/Protocol1_16to20w14infinite.java @@ -47,7 +47,7 @@ public class Protocol1_16to20w14infinite extends BackwardsProtocol tagRewriter; + private final TagRewriter tagRewriter = new TagRewriter<>(this); public Protocol1_16to20w14infinite() { super(ClientboundPackets20w14infinite.class, ClientboundPackets1_16.class, ServerboundPackets20w14infinite.class, ServerboundPackets1_16.class); @@ -57,7 +57,6 @@ public Protocol1_16to20w14infinite() { protected void registerPackets() { super.registerPackets(); - tagRewriter = new TagRewriter<>(this); tagRewriter.register(ClientboundPackets20w14infinite.TAGS, RegistryType.ENTITY); new StatisticsRewriter<>(this).register(ClientboundPackets20w14infinite.STATISTICS); EntityPackets20w14infinite.register(this);