From 411e83b7f14dfefc3f9c6d2840afecf587bc5618 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 27 Jan 2024 15:00:03 +0100 Subject: [PATCH] Updated Fabric libraries and ViaVersion integration --- build.gradle | 2 +- gradle.properties | 4 +-- .../clientcommands/MultiVersionCompat.java | 27 +++++-------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 5f460d1a1..e8569a04c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.4-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' id 'com.modrinth.minotaur' version '2.+' id 'com.github.breadmoirai.github-release' version '2.4.1' diff --git a/gradle.properties b/gradle.properties index 8c6952abc..17779beec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G minecraft_version_list=1.20.3, 1.20.4 minecraft_version_list_presentable=1.20.3 - 1.20.4 yarn_mappings=1.20.4+build.1 - loader_version=0.15.0 + loader_version=0.15.6 # Mod Properties mod_version=2.8.9 @@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx2G # Dependencies # also check this on https://fabricmc.net/develop/ - fabric_version=0.91.1+1.20.4 + fabric_version=0.95.1+1.20.4 clientarguments_version=1.7 betterconfig_version=1.2.1 seedfinding_core_version=1.192.1 diff --git a/src/main/java/net/earthcomputer/clientcommands/MultiVersionCompat.java b/src/main/java/net/earthcomputer/clientcommands/MultiVersionCompat.java index 8dabe3e0c..43024e3ae 100644 --- a/src/main/java/net/earthcomputer/clientcommands/MultiVersionCompat.java +++ b/src/main/java/net/earthcomputer/clientcommands/MultiVersionCompat.java @@ -5,7 +5,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.ModContainer; import net.minecraft.SharedConstants; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; @@ -41,10 +40,9 @@ public boolean doesItemExist(Item item) { public static final MultiVersionCompat INSTANCE = Util.make(() -> { try { FabricLoader loader = FabricLoader.getInstance(); - ModContainer modContainer; - if ((modContainer = loader.getModContainer("viafabric").orElse(null)) != null) { + if (loader.isModLoaded("viafabric")) { return new ViaFabric(); - } else if ((modContainer = loader.getModContainer("viafabricplus").orElse(null)) != null) { + } else if (loader.isModLoaded("viafabricplus")) { return new ViaFabricPlus(); } else { return new None(); @@ -175,38 +173,27 @@ private int doGetProtocolVersion() throws ReflectiveOperationException { } private static final class ViaFabricPlus extends AbstractViaVersion { - private final Field itemReleaseVersionMappingsInstance; private final Method getTargetVersion; private final Method versionEnumGetProtocol; - private final Method itemReleaseVersionMappingsContains; + private final Method itemRegistryDiffKeepItem; private ViaFabricPlus() throws ReflectiveOperationException { Class protocolHack = Class.forName("de.florianmichael.viafabricplus.protocolhack.ProtocolHack"); - Class itemReleaseVersionMappings = Class.forName("de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings"); - itemReleaseVersionMappingsInstance = itemReleaseVersionMappings.getField("INSTANCE"); + Class itemRegistryDiff = Class.forName("de.florianmichael.viafabricplus.fixes.data.ItemRegistryDiff"); getTargetVersion = protocolHack.getMethod("getTargetVersion"); versionEnumGetProtocol = getTargetVersion.getReturnType().getMethod("getProtocol"); - itemReleaseVersionMappingsContains = itemReleaseVersionMappings.getMethod("contains", Item.class, getTargetVersion.getReturnType()); + itemRegistryDiffKeepItem = itemRegistryDiff.getMethod("keepItem", Item.class); } @Override protected Object getCurrentVersion() throws ReflectiveOperationException { - return versionEnumGetProtocol.invoke(getVersionEnum()); - } - - private Object getVersionEnum() throws ReflectiveOperationException { - return getTargetVersion.invoke(null); + return versionEnumGetProtocol.invoke(getTargetVersion.invoke(null)); } @Override public boolean doesItemExist(Item item) { try { - Object instance = itemReleaseVersionMappingsInstance.get(null); - if (instance == null) { - // Quilt initializes commands on startup, allowing this to be called outside a world - return true; - } - return (Boolean) itemReleaseVersionMappingsContains.invoke(instance, item, getVersionEnum()); + return (Boolean) itemRegistryDiffKeepItem.invoke(null, item); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); }