Resolved TODO in EntityDimensionDiff

Added ProtocolTranslator#isCloserTo
This commit is contained in:
FlorianMichael 2024-02-15 02:11:38 +01:00
parent 5f0ac0caea
commit 7d5408f7f9
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 20 additions and 3 deletions

View File

@ -21,6 +21,7 @@ package de.florianmichael.viafabricplus.fixes.data;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
@ -198,11 +199,10 @@ public class EntityDimensionDiff {
}
// If the current version is closer to the version you are looking for
// TODO: Fix
/*if (closestVersion == null || Math.abs(version.ordinal() - currentVersion.ordinal()) < Math.abs(version.ordinal() - closestVersion.ordinal())) {
if (closestVersion == null || ProtocolTranslator.isCloserTo(version, currentVersion, closestVersion)) {
closestVersion = currentVersion;
closestDimensions = currentDimensions;
}*/
}
}
return closestDimensions;

View File

@ -261,6 +261,23 @@ public class ProtocolTranslator {
new ConfigPatcher(viaLegacyConfig, viaLegacyPatches);
}
/**
* Returns true if first is closer to version than second
*
* @param version The version to compare to
* @param first The first version
* @param second The second version
* @return true if first is closer to version than second
*/
public static boolean isCloserTo(final ProtocolVersion version, final ProtocolVersion first, final ProtocolVersion second) {
if (version.getVersionType() == first.getVersionType() || version.getVersionType() == second.getVersionType()) {
return Math.abs(version.getVersion() - first.getVersion()) < Math.abs(version.getVersion() - second.getVersion());
} else {
final int ordinal = version.getVersionType().ordinal();
return Math.abs(ordinal - first.getVersionType().ordinal()) < Math.abs(ordinal - second.getVersionType().ordinal());
}
}
/**
* This method is used to initialize the whole Protocol Translator
*