fix: patch Language instances created by Language.create()

This commit is contained in:
Johannes Frohnmeyer 2023-11-19 14:06:59 +01:00
parent f82ded7e5d
commit 2a371d627f
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 15 additions and 4 deletions

View File

@ -4,10 +4,11 @@ import io.gitlab.jfronny.translater.Translater;
import net.minecraft.client.resource.language.TranslationStorage;
import net.minecraft.util.Language;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(Language.class)
public class LanguageMixin {
@Inject(at = @At("HEAD"), method = "setInstance")
@ -15,7 +16,17 @@ public class LanguageMixin {
if (language instanceof TranslationStorage t) {
TranslationStorageAccessor ta = (TranslationStorageAccessor) t;
ta.setTranslations(Translater.getMap(ta.getTranslations()));
Translater.LOGGER.info("Set translater backend");
}
Translater.LOGGER.info("Set translater backend 2");
} else Translater.LOGGER.warn("Unsupported language configured: " + language);
}
@ModifyArg(
at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Language$1;<init>(Ljava/util/Map;)V"),
method = "create()Lnet/minecraft/util/Language;",
index = 0
)
private static Map<String, String> postCreate(Map<String, String> par1) {
Translater.LOGGER.info("Set translater backend 1");
return Translater.getMap(par1);
}
}