diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index ec615322e..67c4a5774 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -64,7 +64,7 @@ public interface ViaAPI { * @return API version incremented with meaningful API changes */ default int apiVersion() { - return 13; + return 14; } /** diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolManager.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolManager.java index 559425ebb..8c716ac32 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolManager.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/ProtocolManager.java @@ -177,35 +177,49 @@ public interface ProtocolManager { @Nullable Class serverboundPacketsClass); /** - * Returns whether protocol path calculation expects the path to come closer to the expected version with each entry, true by default. + * Sets the max delta the path calculation allows the distance to the target protocol version to increase. *

- * In practice, this means a path will never go to a protocol version that puts it farther from the desired + * If set to 0, protocol paths will have to come closer to the target protocol version with every entry, + * never going farther away from it (1→5→10 and 1→11→10 are ok, 1→20→10 is not ok). + * If set to -1, no distance checks will be applied (1→20→10 is ok). + * + * @param maxPathDeltaIncrease the max delta the path calculation allows the distance to the target protocol version to increase + * @see #onlyCheckLoweringPathEntries() + */ + void setMaxPathDeltaIncrease(int maxPathDeltaIncrease); + + /** + * Returns the max delta the path calculation allows the distance to the target protocol version to increase. 0 by default. + *

+ * In practice, a value of 0 means a path will never go to a protocol version that puts it farther from the desired * server protocol version, even if a path existed. - * If this is set to false, *all* possible paths will be checked until a fitting one is found. + * If this is set to -1, *all* possible paths will be checked until a fitting one is found. *

- * Negative examples if this returns true: + * Negative examples if this returns 0: *

*

- * Negative examples if this returns false: + * Negative examples if this returns -1: *

* - * @return whether protocol path calculation expects the path to come closer to the expected version with each entry + * @return max delta the path calculation allows the distance to the target protocol version to increase */ - boolean onlyCheckLoweringPathEntries(); + int getMaxPathDeltaIncrease(); - /** - * Sets whether protocol path calculation expects the path to come closer to the expected version with each entry. - * - * @param onlyCheckLoweringPathEntries whether protocol path calculation expects the path to come closer to the expected version with each entry - * @see #onlyCheckLoweringPathEntries() - */ - void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries); + @Deprecated/*(forRemoval = true)*/ + default void setOnlyCheckLoweringPathEntries(final boolean onlyCheckLoweringPathEntries) { + setMaxPathDeltaIncrease(onlyCheckLoweringPathEntries ? 0 : -1); + } + + @Deprecated/*(forRemoval = true)*/ + default boolean onlyCheckLoweringPathEntries() { + return getMaxPathDeltaIncrease() != -1; + } /** * Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}. 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 e6f67b5f0..895e82076 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/ProtocolManagerImpl.java @@ -119,7 +119,7 @@ public class ProtocolManagerImpl implements ProtocolManager { private boolean mappingsLoaded; private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(-1); - private boolean onlyCheckLoweringPathEntries = true; + private int maxPathDeltaIncrease; // Only allow lowering path entries by default private int maxProtocolPathSize = 50; public ProtocolManagerImpl() { @@ -317,7 +317,7 @@ public class ProtocolManagerImpl implements ProtocolManager { if (current.containsKey(translatedToVersion)) continue; // Check if the new version is farther away than the current client version - if (onlyCheckLoweringPathEntries && Math.abs(serverVersion - translatedToVersion) > Math.abs(serverVersion - clientVersion)) { + if (maxPathDeltaIncrease != -1 && Math.abs(serverVersion - translatedToVersion) - Math.abs(serverVersion - clientVersion) > maxPathDeltaIncrease) { continue; } @@ -385,13 +385,13 @@ public class ProtocolManagerImpl implements ProtocolManager { } @Override - public void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries) { - this.onlyCheckLoweringPathEntries = onlyCheckLoweringPathEntries; + public void setMaxPathDeltaIncrease(final int maxPathDeltaIncrease) { + this.maxPathDeltaIncrease = Math.max(-1, maxPathDeltaIncrease); } @Override - public boolean onlyCheckLoweringPathEntries() { - return onlyCheckLoweringPathEntries; + public int getMaxPathDeltaIncrease() { + return maxPathDeltaIncrease; } @Override diff --git a/gradle.properties b/gradle.properties index 754512179..63506377e 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.4.0 +projectVersion=4.4.1-SNAPSHOT # Gradle properties org.gradle.daemon=true