Skip to content

Commit

Permalink
Merge branch '1.19.3' into 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerozgen committed Mar 13, 2023
2 parents 1a20768 + 89a0b38 commit 2710696
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 63 deletions.
11 changes: 6 additions & 5 deletions src/main/java/jerozgen/languagereload/LanguageReload.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,29 @@ public static void reloadLanguages() {

// Update book and advancements screens
if (client.currentScreen instanceof BookScreen bookScreen) {
((BookScreenAccessor) bookScreen).setCachedPageIndex(-1);
((BookScreenAccessor) bookScreen).languagereload_setCachedPageIndex(-1);
} else if (client.currentScreen instanceof AdvancementsScreen advancementsScreen) {
((IAdvancementsScreen) advancementsScreen).recreateWidgets();
((IAdvancementsScreen) advancementsScreen).languagereload_recreateWidgets();
}

// Update signs
if (client.world == null) return;
var chunkManager = (ClientChunkManagerAccessor) client.world.getChunkManager();
var chunks = ((ClientChunkMapAccessor) chunkManager.getChunks()).getChunks();
var chunks = ((ClientChunkMapAccessor) chunkManager.languagereload_getChunks()).languagereload_getChunks();
for (int i = 0; i < chunks.length(); i++) {
var chunk = chunks.get(i);
if (chunk == null) continue;
for (var blockEntity : chunk.getBlockEntities().values()) {
if (!(blockEntity instanceof SignBlockEntity sign)) continue;
((SignBlockEntityAccessor) sign).setTextsBeingEdited(null);
((SignBlockEntityAccessor) sign).languagereload_setTextsBeingEdited(null);
}
}
}

public static void reloadSearch() {
var client = MinecraftClient.getInstance();
((MinecraftClientAccessor) client).getSearchManager().reload(client.getResourceManager());
var searchManager = ((MinecraftClientAccessor) client).languagereload_getSearchManager();
searchManager.reload(client.getResourceManager());
}

public static void setLanguage(String language, LinkedList<String> fallbacks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

@Environment(EnvType.CLIENT)
public interface IAdvancementsScreen {
void recreateWidgets();
void languagereload_recreateWidgets();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

@Environment(EnvType.CLIENT)
public interface IAdvancementsTab {
void recreateWidgets();
void languagereload_recreateWidgets();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import jerozgen.languagereload.gui.LanguageEntry;

public interface ILanguageOptionsScreen {
void focusEntry(LanguageEntry entry);
void languagereload_focusEntry(LanguageEntry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@Environment(EnvType.CLIENT)
public interface ITranslationStorage {
@Nullable String getTargetLanguage();
@Nullable String languagereload_getTargetLanguage();

void setTargetLanguage(@Nullable String value);
void languagereload_setTargetLanguage(@Nullable String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW_KEY_SPACE || keyCode == GLFW_KEY_ENTER) {
selectedEntry.toggle();
this.setFocused(null);
((ILanguageOptionsScreen) screen).focusEntry(selectedEntry);
((ILanguageOptionsScreen) screen).languagereload_focusEntry(selectedEntry);
return true;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
return true;
}

return ((EntryListWidgetAccessor) this).isScrolling();
return ((EntryListWidgetAccessor) this).languagereload_isScrolling();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public abstract class AdvancementTabMixin extends DrawableHelper implements IAdv
@Shadow @Final private Map<Advancement, AdvancementWidget> widgets;

@Override
public void recreateWidgets() {
public void languagereload_recreateWidgets() {
widgets.replaceAll((advancement, widget) -> {
var newWidget = new AdvancementWidget(
((AdvancementWidgetAccessor) widget).getTab(),
((AdvancementWidgetAccessor) widget).languagereload_getTab(),
client,
advancement,
Objects.requireNonNull(advancement.getDisplay())
);
newWidget.setProgress(((AdvancementWidgetAccessor) widget).getProgress());
((AdvancementWidgetAccessor) newWidget).setParent(((AdvancementWidgetAccessor) widget).getParent());
((AdvancementWidgetAccessor) newWidget).setChildren(((AdvancementWidgetAccessor) widget).getChildren());
newWidget.setProgress(((AdvancementWidgetAccessor) widget).languagereload_getProgress());
((AdvancementWidgetAccessor) newWidget).languagereload_setParent(((AdvancementWidgetAccessor) widget).languagereload_getParent());
((AdvancementWidgetAccessor) newWidget).languagereload_setChildren(((AdvancementWidgetAccessor) widget).languagereload_getChildren());
return newWidget;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@

@Mixin(AdvancementWidget.class)
public interface AdvancementWidgetAccessor {
@Accessor
AdvancementTab getTab();
@Accessor("tab")
AdvancementTab languagereload_getTab();

@Accessor
AdvancementProgress getProgress();
@Accessor("progress")
AdvancementProgress languagereload_getProgress();

@Accessor
AdvancementWidget getParent();
@Accessor("parent")
AdvancementWidget languagereload_getParent();

@Accessor
void setParent(AdvancementWidget parent);
@Accessor("parent")
void languagereload_setParent(AdvancementWidget parent);

@Accessor
List<AdvancementWidget> getChildren();
@Accessor("children")
List<AdvancementWidget> languagereload_getChildren();

@Mutable
@Accessor
void setChildren(List<AdvancementWidget> children);
@Accessor("children")
void languagereload_setChildren(List<AdvancementWidget> children);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected AdvancementsScreenMixin(Text title) {
}

@Override
public void recreateWidgets() {
public void languagereload_recreateWidgets() {
for (var advancementTab : tabs.values()) {
((IAdvancementsTab) advancementTab).recreateWidgets();
((IAdvancementsTab) advancementTab).languagereload_recreateWidgets();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@Mixin(BookScreen.class)
public interface BookScreenAccessor {
@Accessor
void setCachedPageIndex(int cachedPageIndex);
@Accessor("cachedPageIndex")
void languagereload_setCachedPageIndex(int cachedPageIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@Mixin(ClientChunkManager.class)
public interface ClientChunkManagerAccessor {
@Accessor
ClientChunkManager.ClientChunkMap getChunks();
@Accessor("chunks")
ClientChunkManager.ClientChunkMap languagereload_getChunks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

@Mixin(ClientChunkManager.ClientChunkMap.class)
public interface ClientChunkMapAccessor {
@Accessor
AtomicReferenceArray<WorldChunk> getChunks();
@Accessor("chunks")
AtomicReferenceArray<WorldChunk> languagereload_getChunks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@Mixin(EntryListWidget.class)
public interface EntryListWidgetAccessor {
@Accessor
boolean isScrolling();
@Accessor("scrolling")
boolean languagereload_isScrolling();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -32,6 +33,7 @@ public abstract class KeyboardMixin {
@Shadow
protected abstract void debugError(String key, Object... args);

@Unique
private void processLanguageReloadKeys() {
if (Screen.hasShiftDown()) {
var config = Config.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -28,12 +29,12 @@
public abstract class LanguageOptionsScreenMixin extends GameOptionsScreen implements ILanguageOptionsScreen {
@Shadow @Final private static Text LANGUAGE_WARNING_TEXT;

private LanguageListWidget availableLanguageList;
private LanguageListWidget selectedLanguageList;
private TextFieldWidget searchBox;
private final LinkedList<String> selectedLanguages = new LinkedList<>();
private final Map<String, MovableLanguageEntry> languageEntries = new LinkedHashMap<>();
private LockedLanguageEntry defaultLanguageEntry;
@Unique private LanguageListWidget availableLanguageList;
@Unique private LanguageListWidget selectedLanguageList;
@Unique private TextFieldWidget searchBox;
@Unique private final LinkedList<String> selectedLanguages = new LinkedList<>();
@Unique private final Map<String, MovableLanguageEntry> languageEntries = new LinkedHashMap<>();
@Unique private LockedLanguageEntry defaultLanguageEntry;

LanguageOptionsScreenMixin(Screen parent, GameOptions options, Text title) {
super(parent, options, title);
Expand Down Expand Up @@ -86,6 +87,7 @@ public void setFocused(boolean focused) {
ci.cancel();
}

@Unique
private void onDone(ButtonWidget button) {
if (client == null) return;
client.setScreen(parent);
Expand All @@ -101,20 +103,22 @@ private void onDone(ButtonWidget button) {
}

@Override
public void focusEntry(LanguageEntry entry) {
public void languagereload_focusEntry(LanguageEntry entry) {
((AlwaysSelectedEntryListWidgetAccessor) availableLanguageList).setInFocus(false);
((AlwaysSelectedEntryListWidgetAccessor) selectedLanguageList).setInFocus(false);
entry.getParent().setSelected(entry);
entry.getParent().changeFocus(true);
setFocused(entry.getParent());
}

public void focusSearch() {
@Unique
private void focusSearch() {
((AlwaysSelectedEntryListWidgetAccessor) availableLanguageList).setInFocus(false);
((AlwaysSelectedEntryListWidgetAccessor) selectedLanguageList).setInFocus(false);
setFocused(searchBox);
}

@Unique
private void refresh() {
refreshList(selectedLanguageList, Stream.concat(
selectedLanguages.stream().map(languageEntries::get).filter(Objects::nonNull),
Expand All @@ -129,6 +133,7 @@ private void refresh() {
}));
}

@Unique
private void refreshList(LanguageListWidget list, Stream<? extends LanguageEntry> entries) {
var selectedEntry = list.getSelectedOrNull();
list.setSelected(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Mixin(MinecraftClient.class)
public interface MinecraftClientAccessor {
@Accessor
SearchManager getSearchManager();
@Accessor("searchManager")
SearchManager languagereload_getSearchManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ private static String addFallbackTranslationsToSearchTooltips(Text text) {

var stringBuilder = new StringBuilder(text.getString());
for (String fallbackCode : Config.getInstance().fallbacks) {
((ITranslationStorage) translationStorage).setTargetLanguage(fallbackCode);
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(fallbackCode);
stringBuilder.append('\n').append(text.getString());
}
((ITranslationStorage) translationStorage).setTargetLanguage(Language.DEFAULT_LANGUAGE);
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(Language.DEFAULT_LANGUAGE);
stringBuilder.append('\n').append(text.getString());

((ITranslationStorage) translationStorage).setTargetLanguage(null);
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(null);
return stringBuilder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@Mixin(SignBlockEntity.class)
public interface SignBlockEntityAccessor {
@Accessor
void setTextsBeingEdited(OrderedText[] textsBeingEdited);
@Accessor("textsBeingEdited")
void languagereload_setTextsBeingEdited(OrderedText[] textsBeingEdited);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -25,9 +26,9 @@

@Mixin(TranslatableTextContent.class)
abstract class TranslatableTextContentMixin implements TextContent {
private @Nullable String previousTargetLanguage;
private final Map<String, List<StringVisitable>> separateTranslationsCache = Maps.newHashMap();
private @Nullable List<StringVisitable> savedTranslations;
@Unique private @Nullable String previousTargetLanguage;
@Unique private final Map<String, List<StringVisitable>> separateTranslationsCache = Maps.newHashMap();
@Unique private @Nullable List<StringVisitable> savedTranslations;

@Shadow @Final private String key;
@Shadow private @Nullable Language languageCache;
Expand All @@ -39,7 +40,7 @@ void onUpdateTranslations(CallbackInfo ci) {
if (!Config.getInstance().multilingualItemSearch) return;
if (!(languageCache instanceof TranslationStorage)) return;

var targetLanguage = ((ITranslationStorage) languageCache).getTargetLanguage();
var targetLanguage = ((ITranslationStorage) languageCache).languagereload_getTargetLanguage();
if (Objects.equals(previousTargetLanguage, targetLanguage)) return;

if (targetLanguage == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.util.Language;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -22,9 +23,9 @@

@Mixin(TranslationStorage.class)
abstract class TranslationStorageMixin extends Language implements ITranslationStorage {
private @Nullable String targetLanguage;
private static Map<String, Map<String, String>> separateTranslationsOnLoad;
private Map<String, Map<String, String>> separateTranslations;
@Unique private @Nullable String targetLanguage;
@Unique private static Map<String, Map<String, String>> separateTranslationsOnLoad;
@Unique private Map<String, Map<String, String>> separateTranslations;

@Inject(method = "<init>", at = @At("RETURN"))
void onConstructed(Map<String, String> translations, boolean rightToLeft, CallbackInfo ci) {
Expand Down Expand Up @@ -62,12 +63,12 @@ void onGet(String key, CallbackInfoReturnable<String> cir) {
}

@Override
public @Nullable String getTargetLanguage() {
public @Nullable String languagereload_getTargetLanguage() {
return targetLanguage;
}

@Override
public void setTargetLanguage(@Nullable String value) {
public void languagereload_setTargetLanguage(@Nullable String value) {
targetLanguage = value;
}
}

0 comments on commit 2710696

Please sign in to comment.