Skip to content

Commit

Permalink
fix issue on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jun 9, 2021
1 parent b6b74d1 commit 28a0182
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 51 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package fr.catcore.server.translations.api.mixin.client;

import fr.catcore.server.translations.api.resource.language.SystemDelegatedLanguage;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslationException;
import net.minecraft.util.Language;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.util.List;

@Mixin(TranslatableText.class)
public abstract class TranslatableTextMixin {

@Shadow @Nullable private Language languageCache;

@Shadow @Final private List<StringVisitable> translations;

@Shadow @Final private String key;

@Shadow protected abstract void setTranslation(String translation);

/**
* @author CatCore
*/
@Overwrite
private void updateTranslations() {
Language language = Language.getInstance();
if (language instanceof SystemDelegatedLanguage delegatedLanguage && delegatedLanguage.languageChanged()) {
this.languageCache = language;
this.translations.clear();
String string = language.get(this.key);

try {
this.setTranslation(string);
} catch (TranslationException var4) {
this.translations.clear();
this.translations.add(StringVisitable.plain(string));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package fr.catcore.server.translations.api.resource.language;

import fr.catcore.server.translations.api.ServerTranslations;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.font.TextVisitFactory;
import net.minecraft.text.OrderedText;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Style;
import net.minecraft.util.Language;

import java.util.Optional;

public final class SystemDelegatedLanguage extends Language {
public static final SystemDelegatedLanguage INSTANCE = new SystemDelegatedLanguage();

private Language vanilla = Language.getInstance();

private boolean changed = false;

private SystemDelegatedLanguage() {
}

public void setVanilla(Language language) {
this.vanilla = language;
this.changed = true;
}

public boolean languageChanged() {
return this.changed;
}

@Override
Expand Down Expand Up @@ -48,14 +49,6 @@ private ServerLanguage getSystemLanguage() {

@Override
public OrderedText reorder(StringVisitable text) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return ReorderingUtil.reorder(text, this.isRightToLeft());
} else {
return (visitor) -> {
return text.visit((style, string) -> {
return TextVisitFactory.visitFormatted(string, style, visitor) ? Optional.empty() : StringVisitable.TERMINATE_VISIT;
}, Style.EMPTY).isPresent();
};
}
return this.vanilla.reorder(text);
}
}
2 changes: 1 addition & 1 deletion api/src/main/resources/server_translations_api.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"client": [
"client.LanguageMixin",
"client.I18nMixin"
"client.TranslatableTextMixin"
],
"server": [
"packet.PacketByteBufMixin",
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

class Globals {
static def baseVersion = "1.4.3+1.17"
static def baseVersion = "1.4.4+1.17"
static def mcVersion = "1.17-pre1"
static def yarnVersion = "+build.1"
}
Expand Down

0 comments on commit 28a0182

Please sign in to comment.