From 79f2a87a0fd828949fdea676ebafa80e0c685009 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 2 Jan 2025 11:09:35 +0000 Subject: [PATCH] Migrate to new VFP API, fixes #702 --- .../util/MultiVersionCompat.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/util/MultiVersionCompat.java b/src/main/java/net/earthcomputer/clientcommands/util/MultiVersionCompat.java index b10c6239..34a42960 100644 --- a/src/main/java/net/earthcomputer/clientcommands/util/MultiVersionCompat.java +++ b/src/main/java/net/earthcomputer/clientcommands/util/MultiVersionCompat.java @@ -184,25 +184,27 @@ private int doGetProtocolVersion() throws ReflectiveOperationException { } private static final class ViaFabricPlus extends AbstractViaVersion { + private final Method viaFabricPlusGetImpl; private final Method getTargetVersion; private final Method olderThan; - private final Method itemRegistryDiffKeepItem; + private final Method itemExistsInConnection; private final Object release1_7_2Version; private ViaFabricPlus() throws ReflectiveOperationException { - Class protocolTranslator = Class.forName("de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator"); - Class itemRegistryDiff = Class.forName("de.florianmichael.viafabricplus.fixes.data.ItemRegistryDiff"); + Class viaFabricPlus = Class.forName("com.viaversion.viafabricplus.ViaFabricPlus"); + Class viaFabricPlusBase = Class.forName("com.viaversion.viafabricplus.api.ViaFabricPlusBase"); Class protocolVersion = Class.forName("com.viaversion.viaversion.api.protocol.version.ProtocolVersion"); - getTargetVersion = protocolTranslator.getMethod("getTargetVersion"); - olderThan = getTargetVersion.getReturnType().getMethod("olderThan", getTargetVersion.getReturnType()); - itemRegistryDiffKeepItem = itemRegistryDiff.getMethod("keepItem", Item.class); + viaFabricPlusGetImpl = viaFabricPlus.getMethod("getImpl"); + getTargetVersion = viaFabricPlusBase.getMethod("getTargetVersion"); + olderThan = protocolVersion.getMethod("olderThan", protocolVersion); + itemExistsInConnection = viaFabricPlusBase.getMethod("itemExistsInConnection", Item.class); release1_7_2Version = protocolVersion.getField("v1_7_2").get(null); } @Override public int getProtocolVersion() { try { - final boolean isOlderThan1_7_2 = (boolean) olderThan.invoke(getTargetVersion.invoke(null), release1_7_2Version); + final boolean isOlderThan1_7_2 = (boolean) olderThan.invoke(getTargetVersion.invoke(getImpl()), release1_7_2Version); if (isOlderThan1_7_2) { return V1_7_2; } else { @@ -215,13 +217,21 @@ public int getProtocolVersion() { @Override protected Object getCurrentVersion() throws ReflectiveOperationException { - return getTargetVersion.invoke(null); + return getTargetVersion.invoke(getImpl()); } @Override public boolean doesItemExist(Item item) { try { - return (Boolean) itemRegistryDiffKeepItem.invoke(null, item); + return (Boolean) itemExistsInConnection.invoke(getImpl(), item); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + private Object getImpl() { + try { + return viaFabricPlusGetImpl.invoke(null); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); }