Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Fabric libraries and ViaVersion integration #592

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
Loading