diff --git a/build.gradle b/build.gradle index 4e047be..d5b3dc0 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ repositories { } dependencies { - compileOnly "com.viaversion:viaversion-common:4.10.0-23w51b-SNAPSHOT" + compileOnly "com.viaversion:viaversion-common:4.10.0-24w07a-SNAPSHOT" compileOnly "org.yaml:snakeyaml:2.2" compileOnly "com.google.guava:guava:33.0.0-jre" compileOnly "io.netty:netty-handler:4.1.107.Final" diff --git a/src/main/java/net/raphimc/vialegacy/api/LegacyProtocolVersion.java b/src/main/java/net/raphimc/vialegacy/api/LegacyProtocolVersion.java index 207f7a0..9fbcebd 100644 --- a/src/main/java/net/raphimc/vialegacy/api/LegacyProtocolVersion.java +++ b/src/main/java/net/raphimc/vialegacy/api/LegacyProtocolVersion.java @@ -18,89 +18,83 @@ package net.raphimc.vialegacy.api; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viaversion.api.protocol.version.VersionRange; +import com.viaversion.viaversion.api.protocol.version.SubVersionRange; +import com.viaversion.viaversion.api.protocol.version.VersionType; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import static com.viaversion.viaversion.api.protocol.version.VersionType.*; + public class LegacyProtocolVersion { public static final List PROTOCOLS = new ArrayList<>(); - // Pre Netty - public static final ProtocolVersion c0_0_15a_1 = registerLegacy(-2 << 2 | 1, "c0.0.15a-1"); // this version has no protocol id - public static final ProtocolVersion c0_0_16a_02 = registerLegacy(-3 << 2 | 1, "c0.0.16a-02"); - public static final ProtocolVersion c0_0_18a_02 = registerLegacy(-4 << 2 | 1, "c0.0.18a-02"); - public static final ProtocolVersion c0_0_19a_06 = registerLegacy(-5 << 2 | 1, "c0.0.19a-06"); - public static final ProtocolVersion c0_0_20ac0_27 = registerLegacy(-6 << 2 | 1, "c0.0.20a-c0.27"); - public static final ProtocolVersion c0_28toc0_30 = registerLegacy(-7 << 2 | 1, "c0.28-c0.30"); - public static final ProtocolVersion a1_0_15 = registerLegacy(-13 << 2 | 1, "a1.0.15"); - public static final ProtocolVersion a1_0_16toa1_0_16_2 = registerLegacy(-14 << 2 | 1, "a1.0.16-a1.0.16.2", new VersionRange("a1.0.16", 0, 2)); - public static final ProtocolVersion a1_0_17toa1_0_17_4 = registerLegacy(-27 << 2, "a1.0.17-a1.0.17.4", new VersionRange("a1.0.17", 0, 4)); - public static final ProtocolVersion a1_1_0toa1_1_2_1 = registerLegacy(-2 << 2, "a1.1.0-a1.1.2.1", new VersionRange("a1.1", 0, 2)); - public static final ProtocolVersion a1_2_0toa1_2_1_1 = registerLegacy(-3 << 2, "a1.2.0-a1.2.1.1", new VersionRange("a1.2", 0, 1)); - public static final ProtocolVersion a1_2_2 = registerLegacy(-4 << 2, "a1.2.2"); - public static final ProtocolVersion a1_2_3toa1_2_3_4 = registerLegacy(-5 << 2, "a1.2.3-a1.2.3.4", new VersionRange("a1.2.3", 0, 4)); - public static final ProtocolVersion a1_2_3_5toa1_2_6 = registerLegacy(-6 << 2, "a1.2.3.5-a1.2.6", new VersionRange("a1.2.3", 5, 6)); - public static final ProtocolVersion b1_0tob1_1_1 = registerLegacy(-7 << 2, "b1.0-b1.1.1", new VersionRange("b1.0", 0, 1)); - public static final ProtocolVersion b1_1_2 = registerLegacy(-8 << 2 | 1, "b1.1.2"); // yes its id 8 and incompatible with b1.2-b1.2.2. Thanks mojank - public static final ProtocolVersion b1_2_0tob1_2_2 = registerLegacy(-8 << 2, "b1.2-b1.2.2", new VersionRange("b1.2", 0, 2)); - public static final ProtocolVersion b1_3tob1_3_1 = registerLegacy(-9 << 2, "b1.3-b1.3.1", new VersionRange("b1.3", 0, 1)); - public static final ProtocolVersion b1_4tob1_4_1 = registerLegacy(-10 << 2, "b1.4-b1.4.1", new VersionRange("b1.4", 0, 1)); - public static final ProtocolVersion b1_5tob1_5_2 = registerLegacy(-11 << 2, "b1.5-b1.5.2", new VersionRange("b1.5", 0, 2)); - public static final ProtocolVersion b1_6tob1_6_6 = registerLegacy(-13 << 2, "b1.6-b1.6.6", new VersionRange("b1.6", 0, 6)); - public static final ProtocolVersion b1_7tob1_7_3 = registerLegacy(-14 << 2, "b1.7-b1.7.3", new VersionRange("b1.7", 0, 3)); - public static final ProtocolVersion b1_8tob1_8_1 = registerLegacy(-17 << 2, "b1.8-b1.8.1", new VersionRange("b1.8", 0, 1)); - public static final ProtocolVersion r1_0_0tor1_0_1 = registerLegacy(-22 << 2, "1.0.0-1.0.1", new VersionRange("1.0", 0, 1)); - public static final ProtocolVersion r1_1 = registerLegacy(-23 << 2, "1.1"); - public static final ProtocolVersion r1_2_1tor1_2_3 = registerLegacy(-28 << 2, "1.2.1-1.2.3", new VersionRange("1.2", 1, 3)); - public static final ProtocolVersion r1_2_4tor1_2_5 = registerLegacy(-29 << 2, "1.2.4-1.2.5", new VersionRange("1.2", 4, 5)); - public static final ProtocolVersion r1_3_1tor1_3_2 = registerLegacy(-39 << 2, "1.3.1-1.3.2", new VersionRange("1.3", 1, 2)); - public static final ProtocolVersion r1_4_2 = registerLegacy(-47 << 2, "1.4.2"); - public static final ProtocolVersion r1_4_4tor1_4_5 = registerLegacy(-49 << 2, "1.4.4-1.4.5", new VersionRange("1.4", 4, 5)); - public static final ProtocolVersion r1_4_6tor1_4_7 = registerLegacy(-51 << 2, "1.4.6-1.4.7", new VersionRange("1.4", 6, 7)); - public static final ProtocolVersion r1_5tor1_5_1 = registerLegacy(-60 << 2, "1.5-1.5.1", new VersionRange("1.5", 0, 1)); - public static final ProtocolVersion r1_5_2 = registerLegacy(-61 << 2, "1.5.2"); - public static final ProtocolVersion r1_6_1 = registerLegacy(-73 << 2, "1.6.1"); - public static final ProtocolVersion r1_6_2 = registerLegacy(-74 << 2, "1.6.2"); - public static final ProtocolVersion r1_6_4 = registerLegacy(-78 << 2, "1.6.4"); + public static final ProtocolVersion c0_0_15a_1 = registerLegacy(CLASSIC, 0, "c0.0.15a-1"); // this version has no protocol id + public static final ProtocolVersion c0_0_16a_02 = registerLegacy(CLASSIC, 3, "c0.0.16a-02"); + public static final ProtocolVersion c0_0_18a_02 = registerLegacy(CLASSIC, 4, "c0.0.18a-02"); + public static final ProtocolVersion c0_0_19a_06 = registerLegacy(CLASSIC, 5, "c0.0.19a-06"); + public static final ProtocolVersion c0_0_20ac0_27 = registerLegacy(CLASSIC, 6, "c0.0.20a-c0.27"); + public static final ProtocolVersion c0_28toc0_30 = registerLegacy(CLASSIC, 7, "c0.28-c0.30"); + public static final ProtocolVersion a1_0_15 = registerLegacy(ALPHA_INITIAL, 13, "a1.0.15"); + public static final ProtocolVersion a1_0_16toa1_0_16_2 = registerLegacy(ALPHA_INITIAL, 14, "a1.0.16-a1.0.16.2", new SubVersionRange("a1.0.16", 0, 2)); + public static final ProtocolVersion a1_0_17toa1_0_17_4 = registerLegacy(ALPHA_INITIAL, 27, "a1.0.17-a1.0.17.4", new SubVersionRange("a1.0.17", 0, 4)); + public static final ProtocolVersion a1_1_0toa1_1_2_1 = registerLegacy(ALPHA_LATER, 2, "a1.1.0-a1.1.2.1", new SubVersionRange("a1.1", 0, 2)); + public static final ProtocolVersion a1_2_0toa1_2_1_1 = registerLegacy(ALPHA_LATER, 3, "a1.2.0-a1.2.1.1", new SubVersionRange("a1.2", 0, 1)); + public static final ProtocolVersion a1_2_2 = registerLegacy(ALPHA_LATER, 4, "a1.2.2"); + public static final ProtocolVersion a1_2_3toa1_2_3_4 = registerLegacy(ALPHA_LATER, 5, "a1.2.3-a1.2.3.4", new SubVersionRange("a1.2.3", 0, 4)); + public static final ProtocolVersion a1_2_3_5toa1_2_6 = registerLegacy(ALPHA_LATER, 6, "a1.2.3.5-a1.2.6", new SubVersionRange("a1.2.3", 5, 6)); + public static final ProtocolVersion b1_0tob1_1_1 = registerLegacy(BETA_INITIAL, 7, "b1.0-b1.1.1", new SubVersionRange("b1.0", 0, 1)); + public static final ProtocolVersion b1_1_2 = registerLegacy(BETA_INITIAL, 8, "b1.1.2"); // yes its id 8 and incompatible with b1.2-b1.2.2. Thanks mojank + public static final ProtocolVersion b1_2_0tob1_2_2 = registerLegacy(BETA_LATER, 8, "b1.2-b1.2.2", new SubVersionRange("b1.2", 0, 2)); + public static final ProtocolVersion b1_3tob1_3_1 = registerLegacy(BETA_LATER, 9, "b1.3-b1.3.1", new SubVersionRange("b1.3", 0, 1)); + public static final ProtocolVersion b1_4tob1_4_1 = registerLegacy(BETA_LATER, 10, "b1.4-b1.4.1", new SubVersionRange("b1.4", 0, 1)); + public static final ProtocolVersion b1_5tob1_5_2 = registerLegacy(BETA_LATER, 11, "b1.5-b1.5.2", new SubVersionRange("b1.5", 0, 2)); + public static final ProtocolVersion b1_6tob1_6_6 = registerLegacy(BETA_LATER, 13, "b1.6-b1.6.6", new SubVersionRange("b1.6", 0, 6)); + public static final ProtocolVersion b1_7tob1_7_3 = registerLegacy(BETA_LATER, 14, "b1.7-b1.7.3", new SubVersionRange("b1.7", 0, 3)); + public static final ProtocolVersion b1_8tob1_8_1 = registerLegacy(BETA_LATER, 17, "b1.8-b1.8.1", new SubVersionRange("b1.8", 0, 1)); + public static final ProtocolVersion r1_0_0tor1_0_1 = registerLegacy(RELEASE_INITIAL, 22, "1.0.0-1.0.1", new SubVersionRange("1.0", 0, 1)); + public static final ProtocolVersion r1_1 = registerLegacy(RELEASE_INITIAL, 23, "1.1"); + public static final ProtocolVersion r1_2_1tor1_2_3 = registerLegacy(RELEASE_INITIAL, 28, "1.2.1-1.2.3", new SubVersionRange("1.2", 1, 3)); + public static final ProtocolVersion r1_2_4tor1_2_5 = registerLegacy(RELEASE_INITIAL, 29, "1.2.4-1.2.5", new SubVersionRange("1.2", 4, 5)); + public static final ProtocolVersion r1_3_1tor1_3_2 = registerLegacy(RELEASE_INITIAL, 39, "1.3.1-1.3.2", new SubVersionRange("1.3", 1, 2)); + public static final ProtocolVersion r1_4_2 = registerLegacy(RELEASE_INITIAL, 47, "1.4.2"); + public static final ProtocolVersion r1_4_4tor1_4_5 = registerLegacy(RELEASE_INITIAL, 49, "1.4.4-1.4.5", new SubVersionRange("1.4", 4, 5)); + public static final ProtocolVersion r1_4_6tor1_4_7 = registerLegacy(RELEASE_INITIAL, 51, "1.4.6-1.4.7", new SubVersionRange("1.4", 6, 7)); + public static final ProtocolVersion r1_5tor1_5_1 = registerLegacy(RELEASE_INITIAL, 60, "1.5-1.5.1", new SubVersionRange("1.5", 0, 1)); + public static final ProtocolVersion r1_5_2 = registerLegacy(RELEASE_INITIAL, 61, "1.5.2"); + public static final ProtocolVersion r1_6_1 = registerLegacy(RELEASE_INITIAL, 73, "1.6.1"); + public static final ProtocolVersion r1_6_2 = registerLegacy(RELEASE_INITIAL, 74, "1.6.2"); + public static final ProtocolVersion r1_6_4 = registerLegacy(RELEASE_INITIAL, 78, "1.6.4"); - // Special protocols - public static final ProtocolVersion c0_30cpe = registerLegacy(-7 << 2 | 2, "c0.30 CPE"); - - - public static int protocolCompare(int a, int b) { - if (a >= 0 || b >= 0) { - // If at least one is modern, then a straight compare works fine. - return a - b; + public static final ProtocolVersion c0_30cpe = new ProtocolVersion(SPECIAL, 7, -1, "c0.30 CPE", null) { + @Override + protected Comparator customComparator() { + return (o1, o2) -> { + if (o1 == c0_30cpe) { + o1 = c0_28toc0_30; + } + if (o2 == c0_30cpe) { + o2 = c0_28toc0_30; + } + return o1.compareTo(o2); + }; } - // Both are legacy - final int baseProtocolA = getRealProtocolVersion(a); - final int baseProtocolB = getRealProtocolVersion(b); - if (baseProtocolA != baseProtocolB) { - return baseProtocolA - baseProtocolB; - } - // They're either the same version or one where the protocol overlaps. - final int discriminatorA = a & 3; - final int discriminatorB = b & 3; - return discriminatorB - discriminatorA; // Higher discriminator means older version + }; + + static { + ProtocolVersion.register(c0_30cpe); + PROTOCOLS.add(c0_30cpe); } - public static int getRealProtocolVersion(final int protocolVersion) { - if (protocolVersion >= 0) { - return protocolVersion; - } - - return -(protocolVersion >> 2); + private static ProtocolVersion registerLegacy(final VersionType versionType, final int version, final String name) { + return registerLegacy(versionType, version, name, null); } - - private static ProtocolVersion registerLegacy(final int version, final String name) { - return registerLegacy(version, name, null); - } - - private static ProtocolVersion registerLegacy(final int version, final String name, final VersionRange versionRange) { - final ProtocolVersion protocolVersion = ProtocolVersion.register(version, name, versionRange); + private static ProtocolVersion registerLegacy(final VersionType versionType, final int version, final String name, final SubVersionRange versionRange) { + final ProtocolVersion protocolVersion = new ProtocolVersion(versionType, version, -1, name, versionRange); + ProtocolVersion.register(protocolVersion); PROTOCOLS.add(protocolVersion); return protocolVersion; } diff --git a/src/main/java/net/raphimc/vialegacy/platform/ViaLegacyPlatform.java b/src/main/java/net/raphimc/vialegacy/platform/ViaLegacyPlatform.java index 18de418..cadf124 100644 --- a/src/main/java/net/raphimc/vialegacy/platform/ViaLegacyPlatform.java +++ b/src/main/java/net/raphimc/vialegacy/platform/ViaLegacyPlatform.java @@ -79,8 +79,8 @@ public interface ViaLegacyPlatform { final ProtocolManager protocolManager = Via.getManager().getProtocolManager(); protocolManager.registerProtocol(new Protocol1_8to1_7_6_10(), ProtocolVersion.v1_8, ProtocolVersion.v1_7_6); - protocolManager.registerProtocol(new Protocol1_7_6_10to1_7_2_5(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_7_1); - protocolManager.registerProtocol(new Protocol1_7_2_5to1_6_4(), ProtocolVersion.v1_7_1, LegacyProtocolVersion.r1_6_4); + protocolManager.registerProtocol(new Protocol1_7_6_10to1_7_2_5(), ProtocolVersion.v1_7_6, ProtocolVersion.v1_7_2); + protocolManager.registerProtocol(new Protocol1_7_2_5to1_6_4(), ProtocolVersion.v1_7_2, LegacyProtocolVersion.r1_6_4); protocolManager.registerProtocol(new Protocol1_6_4to1_6_2(), LegacyProtocolVersion.r1_6_4, LegacyProtocolVersion.r1_6_2); protocolManager.registerProtocol(new Protocol1_6_2to1_6_1(), LegacyProtocolVersion.r1_6_2, LegacyProtocolVersion.r1_6_1); protocolManager.registerProtocol(new Protocol1_6_1to1_5_2(), LegacyProtocolVersion.r1_6_1, LegacyProtocolVersion.r1_5_2); @@ -119,7 +119,7 @@ public interface ViaLegacyPlatform { protocolManager.registerProtocol(new Protocolc0_0_16a_02to0_0_15a_1(), LegacyProtocolVersion.c0_0_16a_02, LegacyProtocolVersion.c0_0_15a_1); for (ProtocolVersion version : LegacyProtocolVersion.PROTOCOLS) { - Via.getManager().getProtocolManager().registerBaseProtocol(new EmptyBaseProtocol(), Range.singleton(version.getVersion())); + Via.getManager().getProtocolManager().registerBaseProtocol(new EmptyBaseProtocol(), Range.singleton(version)); } } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/alpha/protocolb1_0_1_1_1toa1_2_3_5_1_2_6/storage/AlphaInventoryTracker.java b/src/main/java/net/raphimc/vialegacy/protocols/alpha/protocolb1_0_1_1_1toa1_2_3_5_1_2_6/storage/AlphaInventoryTracker.java index bffa051..ff2080d 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/alpha/protocolb1_0_1_1_1toa1_2_3_5_1_2_6/storage/AlphaInventoryTracker.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/alpha/protocolb1_0_1_1_1toa1_2_3_5_1_2_6/storage/AlphaInventoryTracker.java @@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.data.ItemList1_6; import net.raphimc.vialegacy.api.model.IdAndData; @@ -33,7 +34,6 @@ import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6. import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.data.CraftingManager; import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.ClientboundPacketsb1_1; import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.types.Typesb1_1; -import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.Protocolc0_30toc0_30cpe; import net.raphimc.vialegacy.protocols.release.protocol1_4_4_5to1_4_2.types.Types1_4_2; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ChunkTracker; @@ -339,8 +339,8 @@ public class AlphaInventoryTracker extends StoredObject { } // Add support for cheating items and classic block placement - public void handleCreativeSetSlot(short slot, Item item) throws Exception { - if (!this.getUser().getProtocolInfo().getPipeline().contains(Protocolc0_30toc0_30cpe.class)) item = fixItem(item); + public void handleCreativeSetSlot(short slot, Item item) { + if (!this.getUser().getProtocolInfo().serverProtocolVersion().equals(LegacyProtocolVersion.c0_30cpe)) item = fixItem(item); if (slot <= 0) return; if (slot <= 4) { diff --git a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_19a_06toc0_0_18a_02/Protocolc0_0_19a_06toc0_0_18a_02.java b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_19a_06toc0_0_18a_02/Protocolc0_0_19a_06toc0_0_18a_02.java index 1cd5526..cd7f58a 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_19a_06toc0_0_18a_02/Protocolc0_0_19a_06toc0_0_18a_02.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_19a_06toc0_0_18a_02/Protocolc0_0_19a_06toc0_0_18a_02.java @@ -35,11 +35,8 @@ public class Protocolc0_0_19a_06toc0_0_18a_02 extends StatelessProtocol { int block = previousRemapper.getReverseMapper().getInt(o); - - if (userConnection.getProtocolInfo().getPipeline().contains(Protocolc0_0_19a_06toc0_0_18a_02.class)) { - if (block != ClassicBlocks.STONE && block != ClassicBlocks.DIRT && block != ClassicBlocks.WOOD && block != ClassicBlocks.SAPLING && block != ClassicBlocks.GRAVEL && block != ClassicBlocks.LOG && block != ClassicBlocks.LEAVES && block != ClassicBlocks.SAND && block != ClassicBlocks.COBBLESTONE) { - block = ClassicBlocks.STONE; - } + if (block != ClassicBlocks.STONE && block != ClassicBlocks.DIRT && block != ClassicBlocks.WOOD && block != ClassicBlocks.SAPLING && block != ClassicBlocks.GRAVEL && block != ClassicBlocks.LOG && block != ClassicBlocks.LEAVES && block != ClassicBlocks.SAND && block != ClassicBlocks.COBBLESTONE) { + block = ClassicBlocks.STONE; } return block; diff --git a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_20a_27toc0_0_19a_06/Protocolc0_27toc0_0_19a_06.java b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_20a_27toc0_0_19a_06/Protocolc0_27toc0_0_19a_06.java index ffb84b3..c588132 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_20a_27toc0_0_19a_06/Protocolc0_27toc0_0_19a_06.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_0_20a_27toc0_0_19a_06/Protocolc0_27toc0_0_19a_06.java @@ -20,13 +20,13 @@ package net.raphimc.vialegacy.protocols.classic.protocolc0_0_20a_27toc0_0_19a_06 import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.protocol.StatelessProtocol; import net.raphimc.vialegacy.api.splitter.PreNettySplitter; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ServerboundPacketsc0_28; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.data.ClassicBlocks; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicBlockRemapper; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.types.Typesc0_30; -import net.raphimc.vialegacy.protocols.classic.protocolc0_0_19a_06toc0_0_18a_02.Protocolc0_0_19a_06toc0_0_18a_02; import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_0_20a_27.ClientboundPacketsc0_20a; public class Protocolc0_27toc0_0_19a_06 extends StatelessProtocol { @@ -66,7 +66,7 @@ public class Protocolc0_27toc0_0_19a_06 extends StatelessProtocol { int block = previousRemapper.getReverseMapper().getInt(o); - if (!userConnection.getProtocolInfo().getPipeline().contains(Protocolc0_0_19a_06toc0_0_18a_02.class)) { + if (userConnection.getProtocolInfo().serverProtocolVersion().equals(LegacyProtocolVersion.c0_0_19a_06)) { if (block != ClassicBlocks.STONE && block != ClassicBlocks.DIRT && block != ClassicBlocks.WOOD && block != ClassicBlocks.SAPLING && block != ClassicBlocks.GRAVEL && block != ClassicBlocks.LOG && block != ClassicBlocks.LEAVES && block != ClassicBlocks.SPONGE && block != ClassicBlocks.GLASS) { block = ClassicBlocks.STONE; } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_0_20a_27/Protocolc0_30toc0_27.java b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_0_20a_27/Protocolc0_30toc0_27.java index e8070ac..d3aea3e 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_0_20a_27/Protocolc0_30toc0_27.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_0_20a_27/Protocolc0_30toc0_27.java @@ -18,13 +18,13 @@ package net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_0_20a_27; import com.viaversion.viaversion.api.connection.UserConnection; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.protocol.StatelessProtocol; import net.raphimc.vialegacy.api.splitter.PreNettySplitter; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ClientboundPacketsc0_28; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.ServerboundPacketsc0_28; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.data.ClassicBlocks; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicBlockRemapper; -import net.raphimc.vialegacy.protocols.classic.protocolc0_0_20a_27toc0_0_19a_06.Protocolc0_27toc0_0_19a_06; public class Protocolc0_30toc0_27 extends StatelessProtocol { @@ -40,7 +40,7 @@ public class Protocolc0_30toc0_27 extends StatelessProtocol { int block = previousRemapper.getReverseMapper().getInt(o); - if (!userConnection.getProtocolInfo().getPipeline().contains(Protocolc0_27toc0_0_19a_06.class)) { + if (userConnection.getProtocolInfo().serverProtocolVersion().equals(LegacyProtocolVersion.c0_0_20ac0_27)) { if (block == ClassicBlocks.GOLD_ORE || block == ClassicBlocks.IRON_ORE || block == ClassicBlocks.COAL_ORE || block == ClassicBlocks.SLAB || block == ClassicBlocks.BRICK || block == ClassicBlocks.TNT || block == ClassicBlocks.BOOKSHELF || block == ClassicBlocks.MOSSY_COBBLESTONE || block == ClassicBlocks.OBSIDIAN) { block = ClassicBlocks.STONE; } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java index f6715e0..9b30738 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/Protocol1_2_1_3to1_1.java @@ -29,12 +29,11 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import net.raphimc.vialegacy.ViaLegacy; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.model.IdAndData; import net.raphimc.vialegacy.api.protocol.StatelessProtocol; import net.raphimc.vialegacy.api.remapper.LegacyItemRewriter; import net.raphimc.vialegacy.api.splitter.PreNettySplitter; -import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.Protocolb1_8_0_1tob1_7_0_3; -import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.Protocola1_0_15toc0_30; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.biome.EndBiomeGenerator; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.biome.NetherBiomeGenerator; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.biome.PlainsBiomeGenerator; @@ -327,9 +326,9 @@ public class Protocol1_2_1_3to1_1 extends StatelessProtocol { final PlayerInfoStorage playerInfoStorage = wrapper.user().get(PlayerInfoStorage.class); - final boolean supportsFlags = wrapper.user().getProtocolInfo().getPipeline().contains(Protocol1_8to1_7_6_10.class); + final boolean supportsFlags = wrapper.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_8); wrapper.write(Type.DOUBLE, supportsFlags ? 0D : playerInfoStorage.posX); // x wrapper.write(Type.DOUBLE, supportsFlags ? 0D : playerInfoStorage.posY + 1.62F); // y @@ -186,7 +185,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { final PlayerInfoStorage playerInfoStorage = wrapper.user().get(PlayerInfoStorage.class); - final boolean supportsFlags = wrapper.user().getProtocolInfo().getPipeline().contains(Protocol1_8to1_7_6_10.class); + final boolean supportsFlags = wrapper.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_8); wrapper.passthrough(Type.DOUBLE); // x wrapper.passthrough(Type.DOUBLE); // stance @@ -207,7 +206,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { final PlayerInfoStorage playerInfoStorage = wrapper.user().get(PlayerInfoStorage.class); - final boolean supportsFlags = wrapper.user().getProtocolInfo().getPipeline().contains(Protocol1_8to1_7_6_10.class); + final boolean supportsFlags = wrapper.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_8); wrapper.write(Type.DOUBLE, supportsFlags ? 0D : playerInfoStorage.posX); // x wrapper.write(Type.DOUBLE, supportsFlags ? 0D : playerInfoStorage.posY + 1.62F); // y @@ -771,7 +770,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { final HandshakeStorage handshakeStorage = wrapper.user().get(HandshakeStorage.class); - wrapper.write(Type.UNSIGNED_BYTE, (short) LegacyProtocolVersion.getRealProtocolVersion(wrapper.user().getProtocolInfo().getServerProtocolVersion())); // protocol id + wrapper.write(Type.UNSIGNED_BYTE, (short) wrapper.user().getProtocolInfo().serverProtocolVersion().getVersion()); // protocol id wrapper.write(Types1_6_4.STRING, wrapper.read(Type.STRING)); // user name wrapper.write(Types1_6_4.STRING, handshakeStorage.getHostname()); // hostname wrapper.write(Type.INT, handshakeStorage.getPort()); // port diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java index 499abb4..90f0d2d 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/storage/ChunkTracker.java @@ -19,14 +19,10 @@ package net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.model.IdAndData; import net.raphimc.vialegacy.api.remapper.AbstractChunkTracker; -import net.raphimc.vialegacy.protocols.beta.protocolb1_2_0_2tob1_1_2.Protocolb1_2_0_2tob1_1_2; -import net.raphimc.vialegacy.protocols.beta.protocolb1_5_0_2tob1_4_0_1.Protocolb1_5_0_2tob1_4_0_1; -import net.raphimc.vialegacy.protocols.beta.protocolb1_6_0_6tob1_5_0_2.Protocolb1_6_0_6tob1_5_0_2; -import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.Protocolb1_8_0_1tob1_7_0_3; -import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.Protocol1_2_1_3to1_1; import java.util.HashMap; import java.util.Map; @@ -216,17 +212,17 @@ public class ChunkTracker extends AbstractChunkTracker { for (int i = 0; i < 16; i++) { this.registerReplacement(new IdAndData(BlockList1_6.lockedChest.blockID, i), new IdAndData(BlockList1_6.bedrock.blockID, 0)); } - if (user.getProtocolInfo().getPipeline().contains(Protocol1_2_1_3to1_1.class)) { + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_1)) { for (int i = 9; i < 16; i++) { this.registerReplacement(new IdAndData(BlockList1_6.doorWood.blockID, i), new IdAndData(BlockList1_6.doorWood.blockID, 8)); this.registerReplacement(new IdAndData(BlockList1_6.doorIron.blockID, i), new IdAndData(BlockList1_6.doorIron.blockID, 8)); } } - if (user.getProtocolInfo().getPipeline().contains(Protocolb1_6_0_6tob1_5_0_2.class)) { + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_5tob1_5_2)) { this.registerReplacement(new IdAndData(BlockList1_6.jukebox.blockID, 2), new IdAndData(BlockList1_6.jukebox.blockID, 1)); } - if (user.getProtocolInfo().getPipeline().contains(Protocolb1_5_0_2tob1_4_0_1.class)) { + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_4tob1_4_1)) { for (int i = 1; i < 8; i++) { this.registerReplacement(new IdAndData(BlockList1_6.sapling.blockID, i), new IdAndData(BlockList1_6.sapling.blockID, 0)); } @@ -234,7 +230,7 @@ public class ChunkTracker extends AbstractChunkTracker { this.registerReplacement(new IdAndData(BlockList1_6.sapling.blockID, i), new IdAndData(BlockList1_6.sapling.blockID, 8)); } } - if (user.getProtocolInfo().getPipeline().contains(Protocolb1_2_0_2tob1_1_2.class)) { + if (user.getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_1_2)) { for (int i = 1; i < 16; i++) { this.registerReplacement(new IdAndData(BlockList1_6.leaves.blockID, i), new IdAndData(BlockList1_6.leaves.blockID, 0)); } @@ -243,7 +239,7 @@ public class ChunkTracker extends AbstractChunkTracker { @Override protected void remapBlock(final IdAndData block, final int x, final int y, final int z) { - if (block.id == BlockList1_6.chest.blockID && this.getUser().getProtocolInfo().getPipeline().contains(Protocolb1_8_0_1tob1_7_0_3.class)) { + if (block.id == BlockList1_6.chest.blockID && this.getUser().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) { byte blockData = 3; int rot1 = this.getBlockNotNull(x, y, z - 1).id; int rot2 = this.getBlockNotNull(x, y, z + 1).id; @@ -311,7 +307,7 @@ public class ChunkTracker extends AbstractChunkTracker { @Override protected void postRemap(DataPalette palette) { - if (this.getUser().getProtocolInfo().getPipeline().contains(Protocolb1_8_0_1tob1_7_0_3.class)) { + if (this.getUser().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) { palette.replaceId(BlockList1_6.chest.blockID << 4, 0); palette.replaceId(BlockList1_6.chest.blockID << 4 | 1, 0); }