Skip to content

Commit

Permalink
Allow JEI to Not be Reloaded on Language Change
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jul 30, 2024
1 parent fcc7a7d commit 24b1a9c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 17 deletions.
5 changes: 0 additions & 5 deletions src/main/java/com/nomiceu/nomilabs/event/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import com.cleanroommc.groovyscript.event.ScriptRunEvent;
import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager;
import com.nomiceu.nomilabs.LabsValues;
import com.nomiceu.nomilabs.NomiLabs;
import com.nomiceu.nomilabs.fluid.registry.LabsFluids;
Expand Down Expand Up @@ -78,10 +77,6 @@ public static void addTooltipNormal(ItemTooltipEvent event) {

@SubscribeEvent
public static void languageChanged(LabsLanguageChangedEvent event) {
// Reload JEI to refresh description text
// noinspection UnstableApiUsage
ReloadableRegistryManager.reloadJei(false);

LabsTooltipHelper.onLanguageChange();
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/nomiceu/nomilabs/mixin/GuiLanguageMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.resource.VanillaResourceType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.FMLClientHandler;

import org.spongepowered.asm.mixin.Final;
Expand All @@ -27,6 +26,7 @@
import com.nomiceu.nomilabs.event.LabsLanguageChangedEvent;
import com.nomiceu.nomilabs.mixinhelper.AccessibleGuiLanguage;
import com.nomiceu.nomilabs.mixinhelper.GuiCustomConfirmOpenLink;
import com.nomiceu.nomilabs.mixinhelper.GuiLanguageShouldReloadJEI;

/**
* Adds Nomi-CEu & Nomi-Labs Translation Pack 'Advertisements' to Language Selection Screen.
Expand Down Expand Up @@ -66,6 +66,9 @@ public abstract class GuiLanguageMixin extends GuiScreen implements AccessibleGu
@Final
private LanguageManager languageManager;

@Shadow
protected GuiScreen parentScreen;

@Inject(method = "<init>", at = @At("TAIL"))
public void savePreviousLang(GuiScreen screen, GameSettings gameSettingsObj, LanguageManager manager,
CallbackInfo ci) {
Expand Down Expand Up @@ -98,7 +101,7 @@ public void drawNewLanguageScreen(int mouseX, int mouseY, float partialTicks, Ca
0xffffff);
drawCenteredString(fontRenderer,
I18n.format(LabsConfig.advanced.languageModifyOption == LabsConfig.Advanced.LanguageModifyOption.LABS ?
"gui.nomilabs.language_pack_labs" : "gui.nomilabs.language_pack_nomi"),
"nomilabs.gui.language_pack_labs" : "nomilabs.gui.language_pack_nomi"),
width / 2, 10 + (int) (fontRenderer.FONT_HEIGHT * 2.5), 0xffffff);
drawCenteredString(fontRenderer, "(" + I18n.format("options.languageWarning") + ")", width / 2,
10 + fontRenderer.FONT_HEIGHT * 4, 0x808080);
Expand All @@ -122,8 +125,9 @@ public void handleCustomActions(GuiButton button, CallbackInfo ci) {
fontRenderer.setBidiFlag(languageManager.isCurrentLanguageBidirectional());
game_settings_3.saveOptions();

// Fire Lang Change Event
MinecraftForge.EVENT_BUS.post(new LabsLanguageChangedEvent(previousLang, language));
mc.displayGuiScreen(new GuiLanguageShouldReloadJEI(parentScreen,
new LabsLanguageChangedEvent(previousLang, language)));
ci.cancel();
break;
case DOWNLOAD_PACK_BTN_ID:
mc.displayGuiScreen(new GuiCustomConfirmOpenLink(this, TRANSLATIONS_DOWNLOAD, downloadPackNote,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public void showIsCustomRecipe(CallbackInfo ci) {
buttons.add(new JeiButton(166, 2, 10, 10)
.setTextures(GuiTextures.INFO_ICON)
.setTooltipBuilder(lines -> lines.add(recipe.isGroovyRecipe() ?
LabsTranslate.translate("gui.nomilabs.recipes.tooltip.gs_recipe") :
LabsTranslate.translate("gui.nomilabs.recipes.tooltip.ct_recipe")))
LabsTranslate.translate("nomilabs.gui.recipes.tooltip.gs_recipe") :
LabsTranslate.translate("nomilabs.gui.recipes.tooltip.ct_recipe")))
.setClickAction((mc, x, y, button) -> false)
.setActiveSupplier(creativeTweaker));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nomiceu.nomilabs.mixinhelper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -55,6 +54,7 @@ public GuiCustomConfirmOpenLink(GuiYesNoCallback parentScreen, String linkText,
this.listLines = new ArrayList<>();
}

@Override
public void initGui() {
super.initGui();
buttonList.clear();
Expand All @@ -70,13 +70,15 @@ private void makeButton(int id, int xOffset, String displayText) {
buttonList.add(new GuiButton(id, width / 2 - 50 + xOffset, height / 6 + 96, 100, 20, displayText));
}

protected void actionPerformed(GuiButton button) throws IOException {
@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 2)
setClipboardString(linkText);

parentScreen.confirmClicked(button.id == 0, parentButtonClickedId);
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.nomiceu.nomilabs.mixinhelper;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.jetbrains.annotations.NotNull;

import com.cleanroommc.groovyscript.registry.ReloadableRegistryManager;
import com.nomiceu.nomilabs.event.LabsLanguageChangedEvent;
import com.nomiceu.nomilabs.util.LabsTranslate;

@SideOnly(Side.CLIENT)
public class GuiLanguageShouldReloadJEI extends GuiYesNo {

protected final GuiScreen parent;
protected final LabsLanguageChangedEvent event;
protected final List<String> descLines = new ArrayList<>();

/**
* @param parent The parent screen of the GuiLanguage instance that is creating this GUI.
* @param event Event to fire
*/
public GuiLanguageShouldReloadJEI(GuiScreen parent, LabsLanguageChangedEvent event) {
// Parent Callback will never happen, just insert default id 0
super(parent, LabsTranslate.translate("nomilabs.gui.language_jei.title"), "", 0);
this.event = event;
this.parent = parent;
}

@Override
public void initGui() {
super.initGui();
descLines.clear();
addToList("nomilabs.gui.language_jei.desc.1");
addToList("nomilabs.gui.language_jei.desc.2");
}

private void addToList(String key) {
descLines.addAll(fontRenderer.listFormattedStringToWidth(LabsTranslate.translate(key), width - 50));
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
int i = 90;

for (String s : descLines) {
drawCenteredString(fontRenderer, s, width / 2, i, 0xFFFFFF);
i += fontRenderer.FONT_HEIGHT;
}
}

@Override
protected void actionPerformed(@NotNull GuiButton button) {
if (button.id == 0) {
// Reload JEI to refresh description text
// noinspection UnstableApiUsage
ReloadableRegistryManager.reloadJei(false);
}

// Fire Lang Change Event (AFTER JEI RELOAD)
MinecraftForge.EVENT_BUS.post(event);

mc.displayGuiScreen(parent);
}
}
12 changes: 8 additions & 4 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,21 @@ config.nomilabs.advanced.difficulty.normal_override=Difficulty Override Normal
config.nomilabs.advanced.difficulty.expert_override=Difficulty Override Expert

# GUI
gui.nomilabs.recipes.tooltip.ct_recipe=CraftTweaker Recipe.
gui.nomilabs.recipes.tooltip.gs_recipe=GroovyScript Recipe.
nomilabs.gui.recipes.tooltip.ct_recipe=CraftTweaker Created Recipe
nomilabs.gui.recipes.tooltip.gs_recipe=GroovyScript Created Recipe

gui.nomilabs.language_pack_nomi=§bTranslation Pack for §dNomi-CEu§b Available! See Below!§r
gui.nomilabs.language_pack_labs=§bTranslation Pack for §dNomi-Labs§b Available! See Below!§r
nomilabs.gui.language_pack_nomi=§bTranslation Pack for §dNomi-CEu§b Available! See Below!§r
nomilabs.gui.language_pack_labs=§bTranslation Pack for §dNomi-Labs§b Available! See Below!§r
nomilabs.gui.language.download=Download Translation Pack
nomilabs.gui.language.gh=Available Languages
nomilabs.gui.language.download.note.labs=§7Download the 'nomi-labs' Zip!§r
nomilabs.gui.language.download.note.nomi=§7Download the 'nomi-ceu' Zip!§r
nomilabs.gui.language.exit=Apply and Exit

nomilabs.gui.language_jei.title=§lShould JEI be Reloaded?§r
nomilabs.gui.language_jei.desc.1=Reloading §bJEI§r ensures that category titles and descriptions are translated to your chosen language.
nomilabs.gui.language_jei.desc.2=However, Reloading JEI will take a §ccouple seconds§r to perform.

# Custom Fluids
fluid.uranium233=Uranium 233
fluid.plutonium2=Plutonium
Expand Down

0 comments on commit 24b1a9c

Please sign in to comment.