3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-03 08:41:05 +02:00

Allow for more control over max path distance delta increase

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-07-28 11:29:02 +02:00
Ursprung 22daa60eb6
Commit e194d27bea
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
4 geänderte Dateien mit 36 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -64,7 +64,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes * @return API version incremented with meaningful API changes
*/ */
default int apiVersion() { default int apiVersion() {
return 13; return 14;
} }
/** /**

Datei anzeigen

@ -177,35 +177,49 @@ public interface ProtocolManager {
@Nullable Class<S> serverboundPacketsClass); @Nullable Class<S> 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.
* <p> * <p>
* 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 (1510 and 11110 are ok, 12010 is not ok).
* If set to -1, no distance checks will be applied (12010 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.
* <p>
* 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. * 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.
* <p> * <p>
* Negative examples if this returns true: * Negative examples if this returns 0:
* <ul> * <ul>
* A possible path from 3 to 5 in order of 3105 will be dismissed. * A possible path from 3 to 5 in order of 3105 will be dismissed.
* A possible path from 5 to 3 in order of 503 will be dismissed. * A possible path from 5 to 3 in order of 503 will be dismissed.
* </ul> * </ul>
* <p> * <p>
* Negative examples if this returns false: * Negative examples if this returns -1:
* <ul> * <ul>
* While searching for a path from 3 to 5, 321 could be checked first before 345 is found. * While searching for a path from 3 to 5, 321 could be checked first before 345 is found.
* While searching for a path from 5 to 3, 567 could be checked first before 543 is found. * While searching for a path from 5 to 3, 567 could be checked first before 543 is found.
* </ul> * </ul>
* *
* @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();
/** @Deprecated/*(forRemoval = true)*/
* Sets whether protocol path calculation expects the path to come closer to the expected version with each entry. default void setOnlyCheckLoweringPathEntries(final boolean onlyCheckLoweringPathEntries) {
* setMaxPathDeltaIncrease(onlyCheckLoweringPathEntries ? 0 : -1);
* @param onlyCheckLoweringPathEntries whether protocol path calculation expects the path to come closer to the expected version with each entry }
* @see #onlyCheckLoweringPathEntries()
*/ @Deprecated/*(forRemoval = true)*/
void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries); default boolean onlyCheckLoweringPathEntries() {
return getMaxPathDeltaIncrease() != -1;
}
/** /**
* Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}. * Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}.

Datei anzeigen

@ -119,7 +119,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
private boolean mappingsLoaded; private boolean mappingsLoaded;
private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(-1); private ServerProtocolVersion serverProtocolVersion = new ServerProtocolVersionSingleton(-1);
private boolean onlyCheckLoweringPathEntries = true; private int maxPathDeltaIncrease; // Only allow lowering path entries by default
private int maxProtocolPathSize = 50; private int maxProtocolPathSize = 50;
public ProtocolManagerImpl() { public ProtocolManagerImpl() {
@ -317,7 +317,7 @@ public class ProtocolManagerImpl implements ProtocolManager {
if (current.containsKey(translatedToVersion)) continue; if (current.containsKey(translatedToVersion)) continue;
// Check if the new version is farther away than the current client version // 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; continue;
} }
@ -385,13 +385,13 @@ public class ProtocolManagerImpl implements ProtocolManager {
} }
@Override @Override
public void setOnlyCheckLoweringPathEntries(boolean onlyCheckLoweringPathEntries) { public void setMaxPathDeltaIncrease(final int maxPathDeltaIncrease) {
this.onlyCheckLoweringPathEntries = onlyCheckLoweringPathEntries; this.maxPathDeltaIncrease = Math.max(-1, maxPathDeltaIncrease);
} }
@Override @Override
public boolean onlyCheckLoweringPathEntries() { public int getMaxPathDeltaIncrease() {
return onlyCheckLoweringPathEntries; return maxPathDeltaIncrease;
} }
@Override @Override

Datei anzeigen

@ -1,5 +1,5 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts # 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 # Gradle properties
org.gradle.daemon=true org.gradle.daemon=true