Skip to content

Commit

Permalink
impl conditional-mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Oct 19, 2024
1 parent ea1a0e1 commit 2284922
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 30 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
maven { url "https://maven.blamejared.com" }
maven { url "https://api.modrinth.com/maven" }
maven { url "https://maven.su5ed.dev/releases" }
maven { url 'https://maven.fallenbreath.me/releases' }
}

dependencies {
Expand All @@ -22,9 +23,8 @@ dependencies {
mappings "dev.architectury:yarn-mappings-patch-neoforge:${project.yarn_patch}"
}
neoForge "net.neoforged:neoforge:${project.neoforge_version}"

modImplementation(include("me.fallenbreath:conditional-mixin-neoforge:0.6.3"))
modCompileOnly("org.embeddedt:embeddium-1.21.1:1.0.12-beta.401+mc1.21.1")

modCompileOnly("maven.modrinth:sodium:mc1.21-0.6.0-beta.2-neoforge")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package io.github.foundationgames.animatica.mixin;

import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.neoforged.fml.loading.FMLLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import io.github.foundationgames.animatica.Animatica;
import me.fallenbreath.conditionalmixin.api.mixin.RestrictiveMixinConfigPlugin;

import java.util.List;
import java.util.Set;

public class AnimaticaMixinConfigPlugin implements IMixinConfigPlugin {
private final Object2BooleanMap<String> conditionalMixins = new Object2BooleanOpenHashMap<>();

@Override
public void onLoad(String mixinPackage) {
boolean sodiumInstalled = FMLLoader.getLoadingModList().getModFileById("sodium") != null;
this.conditionalMixins.put("io.github.foundationgames.animatica.mixin.sodium.SodiumGameOptionPagesMixin", sodiumInstalled);
}

public class AnimaticaMixinConfigPlugin extends RestrictiveMixinConfigPlugin {
@Override
public String getRefMapperConfig() {
return "";
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return this.conditionalMixins.getOrDefault(mixinClassName, true);
protected void onRestrictionCheckFailed(String mixinClassName, String reason) {
Animatica.LOG.error("Disabled mixin {} due to {}", mixinClassName, reason);
}

@Override
Expand All @@ -36,16 +24,6 @@ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

return List.of();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.foundationgames.animatica.mixin.sodium;

import io.github.foundationgames.animatica.config.AnimaticaConfig;
import me.fallenbreath.conditionalmixin.api.annotation.Condition;
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
import net.caffeinemc.mods.sodium.client.gui.SodiumGameOptionPages;
import net.caffeinemc.mods.sodium.client.gui.SodiumGameOptions;
import net.caffeinemc.mods.sodium.client.gui.options.*;
Expand All @@ -19,6 +21,7 @@

import java.util.List;

@Restriction(require = @Condition("sodium"))
@Mixin(value = SodiumGameOptionPages.class, remap = false)
public abstract class SodiumGameOptionPagesMixin {
@Shadow @Final private static SodiumOptionsStorage sodiumOpts;
Expand Down

0 comments on commit 2284922

Please sign in to comment.