Skip to content

Commit

Permalink
Update to Minecraft 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerozgen committed Jun 13, 2024
1 parent 413fb34 commit bf0a9ec
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 58 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
fabric_version=0.98.0+1.20.6
fabric_version=0.100.1+1.21

# Mod Properties
mod_version=1.6.1+1.20.6
mod_version=1.6.1+1.21
maven_group=jerozgen
archives_base_name=language-reload

# Dependencies
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=10.0.0-beta.1
modmenu_version=11.0.0-beta.1
9 changes: 1 addition & 8 deletions src/main/java/jerozgen/languagereload/LanguageReload.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public class LanguageReload {
public static void reloadLanguages() {
var client = MinecraftClient.getInstance();

// Reload language and search managers
// Reload language manager
client.getLanguageManager().reload(client.getResourceManager());
reloadSearch();

// Update window title and chat
client.updateWindowTitle();
Expand Down Expand Up @@ -65,12 +64,6 @@ public static void reloadLanguages() {
}
}

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

public static void setLanguage(String language, LinkedList<String> fallbacks) {
var client = MinecraftClient.getInstance();
var languageManager = client.getLanguageManager();
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/jerozgen/languagereload/config/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.SimpleOptionsScreen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.text.Text;

@Environment(EnvType.CLIENT)
public class ConfigScreen extends SimpleOptionsScreen {
public class ConfigScreen extends GameOptionsScreen {
private static final SimpleOption<Boolean> MULTILINGUAL_SEARCH = SimpleOption.ofBoolean(
"options.languagereload.multilingualItemSearch",
SimpleOption.constantTooltip(Text.translatable("options.languagereload.multilingualItemSearch.tooltip")),
Expand All @@ -22,11 +22,14 @@ public class ConfigScreen extends SimpleOptionsScreen {
});

public ConfigScreen(Screen parent) {
super(
parent,
MinecraftClient.getInstance().options,
Text.translatable("options.languagereload.title"),
new SimpleOption[]{MULTILINGUAL_SEARCH});
super(parent, MinecraftClient.getInstance().options, Text.translatable("options.languagereload.title"));
MULTILINGUAL_SEARCH.setValue(Config.getInstance().multilingualItemSearch);
}

@Override
protected void addOptions() {
if (body != null) {
body.addAll(MULTILINGUAL_SEARCH);
}
}
}
16 changes: 8 additions & 8 deletions src/main/java/jerozgen/languagereload/gui/LanguageEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public class LanguageEntry extends AlwaysSelectedEntryListWidget.Entry<LanguageE
private static final Text DEFAULT_LANGUAGE_TOOLTIP = Text.translatable("language.default.tooltip");

private static final ButtonTextures ADD_TEXTURES = new ButtonTextures(
new Identifier(LanguageReload.MOD_ID, "language_selection/add"),
new Identifier(LanguageReload.MOD_ID, "language_selection/add_highlighted"));
Identifier.of(LanguageReload.MOD_ID, "language_selection/add"),
Identifier.of(LanguageReload.MOD_ID, "language_selection/add_highlighted"));
private static final ButtonTextures REMOVE_TEXTURES = new ButtonTextures(
new Identifier(LanguageReload.MOD_ID, "language_selection/remove"),
new Identifier(LanguageReload.MOD_ID, "language_selection/remove_highlighted"));
Identifier.of(LanguageReload.MOD_ID, "language_selection/remove"),
Identifier.of(LanguageReload.MOD_ID, "language_selection/remove_highlighted"));
private static final ButtonTextures MOVE_UP_TEXTURES = new ButtonTextures(
new Identifier(LanguageReload.MOD_ID, "language_selection/move_up"),
new Identifier(LanguageReload.MOD_ID, "language_selection/move_up_highlighted"));
Identifier.of(LanguageReload.MOD_ID, "language_selection/move_up"),
Identifier.of(LanguageReload.MOD_ID, "language_selection/move_up_highlighted"));
private static final ButtonTextures MOVE_DOWN_TEXTURES = new ButtonTextures(
new Identifier(LanguageReload.MOD_ID, "language_selection/move_down"),
new Identifier(LanguageReload.MOD_ID, "language_selection/move_down_highlighted"));
Identifier.of(LanguageReload.MOD_ID, "language_selection/move_down"),
Identifier.of(LanguageReload.MOD_ID, "language_selection/move_down_highlighted"));

private final MinecraftClient client = MinecraftClient.getInstance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ void onConstructed(Screen parent, GameOptions options, LanguageManager languageM
selectedLanguages.addAll(Config.getInstance().fallbacks);
languageManager.getAllLanguages().forEach((code, language) ->
languageEntries.put(code, new LanguageEntry(this::refresh, code, language, selectedLanguages)));

layout.setHeaderHeight(48);
layout.setFooterHeight(53);
}

@Inject(method = "init", at = @At("HEAD"), cancellable = true)
void onInit(CallbackInfo ci) {
@Inject(method = "initBody", at = @At("HEAD"), cancellable = true)
void onInitBody(CallbackInfo ci) {
var listWidth = Math.min(width / 2 - 4, 200);
availableLanguageList = new LanguageListWidget(client, it(), listWidth, height, Text.translatable("pack.available.title"));
selectedLanguageList = new LanguageListWidget(client, it(), listWidth, height, Text.translatable("pack.selected.title"));
availableLanguageList.setX(width / 2 - 4 - listWidth);
selectedLanguageList.setX(width / 2 + 4);
layout.addBody(availableLanguageList);
layout.addBody(selectedLanguageList);
refresh();

layout.setHeaderHeight(48);
layout.setFooterHeight(53);

super.init();
ci.cancel();
}

Expand All @@ -72,8 +72,6 @@ public void setFocused(boolean focused) {
};
searchBox.setChangedListener(__ -> refresh());

refresh();

var header = layout.addHeader(DirectionalLayoutWidget.vertical().spacing(5));
header.getMainPositioner().alignHorizontalCenter();
header.add(new TextWidget(title, textRenderer));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import jerozgen.languagereload.access.ILanguage;
import jerozgen.languagereload.access.ITranslationStorage;
import jerozgen.languagereload.config.Config;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.search.SearchManager;
import net.minecraft.text.Text;
import net.minecraft.util.Language;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(value = MinecraftClient.class, priority = 990)
abstract class MinecraftClientMixin {
@ModifyExpressionValue(method = {"method_1581" /* Creative Inventory */, "method_53866" /* Recipe Book */},
at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;getString()Ljava/lang/String;"))
private static String addFallbackTranslationsToSearchTooltips(String original, Text text) {
@Mixin(value = SearchManager.class, priority = 990)
abstract class SearchManagerMixin {
@ModifyExpressionValue(method = "method_60363", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;getString()Ljava/lang/String;"))
private static String addFallbackTranslationsToSearchTooltips(String original, Text tooltip) {
if (Config.getInstance() == null) return original;
if (!Config.getInstance().multilingualItemSearch) return original;

Expand All @@ -24,7 +23,7 @@ private static String addFallbackTranslationsToSearchTooltips(String original, T
var stringBuilder = new StringBuilder(original);
for (String fallbackCode : Config.getInstance().fallbacks) {
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(fallbackCode);
stringBuilder.append('\n').append(text.getString());
stringBuilder.append('\n').append(tooltip.getString());
}

((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"depends": {
"fabric-resource-loader-v0": "*",
"fabricloader": ">=0.15.10",
"minecraft": ">=1.20.5"
"minecraft": ">=1.21"
},
"suggests": {
"modmenu": "*"
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/languagereload.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"LanguageManagerMixin",
"LanguageMixin",
"LanguageOptionsScreenMixin",
"MinecraftClientAccessor",
"MinecraftClientMixin",
"RecipeBookWidgetMixin",
"SearchManagerMixin",
"SignTextAccessor",
"TextDisplayEntityAccessor",
"TranslatableTextContentMixin",
Expand Down

0 comments on commit bf0a9ec

Please sign in to comment.