Properly disable mixins

This commit is contained in:
JFronny 2020-07-18 18:23:25 +02:00
parent 292f93a7bf
commit 72e196815e
7 changed files with 78 additions and 9 deletions

View File

@ -31,7 +31,7 @@ dependencies {
modCompile "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
include "me.sargunvohra.mcmods:autoconfig1u:3.2.0-unstable"
modApi "me.shedaniel.cloth:config-2:4.6.0"
include "me.shedaniel.cloth:config-2:4.5.6"
include "me.shedaniel.cloth:config-2:4.6.0"
modCompile("io.github.prospector:modmenu:1.14.5+build.30")
}

View File

@ -0,0 +1,57 @@
package io.gitlab.jfronny.translater;
import io.gitlab.jfronny.translater.mixin.MixinLanguage;
import io.gitlab.jfronny.translater.mixin.MixinMinecraftClient;
import io.gitlab.jfronny.translater.mixin.MixinSplashScreen;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Objects;
import java.util.Set;
public class MixinPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
ModInit.loadCfg();
if (Objects.equals(mixinClassName, MixinLanguage.class.getName()))
return true;
else if (Objects.equals(mixinClassName, MixinMinecraftClient.class.getName()))
return ModInit.Gui();
else if (Objects.equals(mixinClassName, MixinSplashScreen.class.getName()))
return ModInit.Gui();
else
throw new IllegalStateException("Unrecognized mixin! This should never happen");
}
@Override
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) {
}
}

View File

@ -14,9 +14,15 @@ public class ModInit implements ClientModInitializer {
private static final Logger logger = LogManager.getFormatterLogger(MOD_ID);
public static Cfg cfg;
public static void loadCfg() {
if (cfg == null) {
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
}
}
public ModInit() {
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
cfg = AutoConfig.getConfigHolder(Cfg.class).getConfig();
loadCfg();
}
public static void Log(String msg) {
@ -33,4 +39,11 @@ public class ModInit implements ClientModInitializer {
}
public static TransformingMap map = null;
public static boolean Gui() {
return cfg.renderProgress == Cfg.progressMode.Full;
}
public static boolean Cli() {
return cfg.renderProgress == Cfg.progressMode.Full || cfg.renderProgress == Cfg.progressMode.Console;
}
}

View File

@ -26,10 +26,10 @@ public class TransformingMap implements Map<String, String> {
initMax = strings.size();
initializing = true;
for (String value : strings) {
if (ModInit.cfg.renderProgress == Cfg.progressMode.Console || ModInit.cfg.renderProgress == Cfg.progressMode.Full) {
if (ModInit.Cli() || ModInit.Gui()) {
initI++;
ModInit.Log("Transforming " + initI + "/" + initMax);
if (ModInit.cfg.renderProgress == Cfg.progressMode.Full && initI % 10 == 0)
if (ModInit.Gui() && initI % 10 == 0)
((IMClient)MinecraftClient.getInstance()).render();
}
transformer.transform(value);

View File

@ -87,7 +87,7 @@ public class YnTransformer extends CachingTransformer {
currentLang = newLang;
}
currentState = api.translationApi().translate(currentState, startLang).text();
if (ModInit.cfg.renderProgress == Cfg.progressMode.Console || ModInit.cfg.renderProgress == Cfg.progressMode.Full)
if (ModInit.Cli())
ModInit.Log("Transformed: \"" + str + "\" to: \"" + currentState + "\"");
return currentState;
} catch (Exception e) {

View File

@ -1,7 +1,6 @@
package io.gitlab.jfronny.translater.mixin;
import com.google.gson.JsonParser;
import io.gitlab.jfronny.translater.Cfg;
import io.gitlab.jfronny.translater.ModInit;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;
@ -18,7 +17,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.awt.*;
import java.util.Collections;
@Mixin(SplashScreen.class)
@ -28,7 +26,7 @@ public abstract class MixinSplashScreen extends Overlay {
@Inject(at = @At("RETURN"), method = "renderProgressBar")
private void RenderTrnslProgress(MatrixStack matrixStack, int i, int j, int k, int l, float f, CallbackInfo ci) {
if (ModInit.cfg.renderProgress == Cfg.progressMode.Full && ModInit.map != null && ModInit.map.initializing) {
if (ModInit.map != null && ModInit.map.initializing) {
renderer.draw(matrixStack, "Transforming " + ModInit.map.initI + "/" + ModInit.map.initMax, 10, 10, 0);
}
}

View File

@ -3,6 +3,7 @@
"minVersion": "0.8",
"package": "io.gitlab.jfronny.translater.mixin",
"compatibilityLevel": "JAVA_8",
"plugin": "io.gitlab.jfronny.translater.MixinPlugin",
"client": [
"MixinLanguage",
"MixinMinecraftClient",