Skip to content

Commit

Permalink
Do not silently crash when incompatible mod is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jul 16, 2024
1 parent f0aace3 commit 40b3ab3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ plugins {
}

val MINECRAFT_VERSION by extra { "1.21" }
val NEOFORGE_VERSION by extra { "21.0.57-beta" }
val FABRIC_LOADER_VERSION by extra { "0.15.11" }
val NEOFORGE_VERSION by extra { "21.0.95-beta" }
val FABRIC_LOADER_VERSION by extra { "0.16.0" }
val FABRIC_API_VERSION by extra { "0.100.4+1.21" }

// This value can be set to null to disable Parchment.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package net.caffeinemc.mods.sodium.client.services;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Path;

public interface PlatformInfoAccess {
Expand Down Expand Up @@ -41,4 +33,9 @@ static PlatformInfoAccess getInstance() {
* Returns if the platform has a early loading screen.
*/
boolean platformHasEarlyLoadingScreen();

/**
* Returns if a mod is in the mods folder during loading.
*/
boolean isModInLoadingList(String modId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.caffeinemc.mods.sodium.mixin;

import net.caffeinemc.mods.sodium.client.data.config.MixinConfig;
import net.caffeinemc.mods.sodium.client.services.PlatformInfoAccess;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.tree.ClassNode;
Expand All @@ -17,6 +18,7 @@ public class SodiumMixinPlugin implements IMixinConfigPlugin {

private final Logger logger = LogManager.getLogger("Sodium");
private MixinConfig config;
private boolean dependencyResolutionFailed;

@Override
public void onLoad(String mixinPackage) {
Expand All @@ -26,6 +28,12 @@ public void onLoad(String mixinPackage) {
throw new RuntimeException("Could not load configuration file for Sodium", e);
}

this.dependencyResolutionFailed = PlatformInfoAccess.getInstance().isModInLoadingList("embeddium");

if (dependencyResolutionFailed) {
this.logger.error("Not applying any Sodium mixins; dependency resolution has failed.");
}

this.logger.info("Loaded configuration file for Sodium: {} options available, {} override(s) found",
this.config.getOptionCount(), this.config.getOptionOverrideCount());
}
Expand All @@ -37,6 +45,10 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (dependencyResolutionFailed) {
return false;
}

if (!mixinClassName.startsWith(MIXIN_PACKAGE_ROOT)) {
this.logger.error("Expected mixin '{}' to start with package root '{}', treating as foreign and " +
"disabling!", mixinClassName, MIXIN_PACKAGE_ROOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public boolean isFlawlessFramesActive() {
public boolean platformHasEarlyLoadingScreen() {
return false;
}

@Override
public boolean isModInLoadingList(String modId) {
return FabricLoader.getInstance().isModLoaded(modId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.neoforged.fml.loading.FMLConfig;
import net.neoforged.fml.loading.FMLLoader;
import net.neoforged.fml.loading.FMLPaths;
import net.neoforged.fml.loading.LoadingModList;

import java.nio.file.Path;

Expand Down Expand Up @@ -32,4 +33,9 @@ public boolean isFlawlessFramesActive() {
public boolean platformHasEarlyLoadingScreen() {
return FMLConfig.getBoolConfigValue(FMLConfig.ConfigValue.EARLY_WINDOW_CONTROL);
}

@Override
public boolean isModInLoadingList(String modId) {
return LoadingModList.get().getModFileById(modId) != null;
}
}
8 changes: 8 additions & 0 deletions neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ versionRange = "[1.20.4,1.21.1)"
ordering = "NONE"
side = "CLIENT"

[[dependencies.sodium]]
modId = "embeddium"
type = "incompatible"
reason = "Sodium and Embeddium cannot be used together. Please remove Embeddium."
versionRange = "[0.0.1,)"
ordering = "NONE"
side = "CLIENT"

[[mixins]]
config = "sodium.mixins.json"

Expand Down

0 comments on commit 40b3ab3

Please sign in to comment.