-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/jerozgen/languagereload/mixin/LanguageSelectionListWidgetAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package jerozgen.languagereload.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.option.LanguageOptionsScreen; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(LanguageOptionsScreen.LanguageSelectionListWidget.class) | ||
public interface LanguageSelectionListWidgetAccessor { | ||
@Invoker("<init>") | ||
static LanguageOptionsScreen.LanguageSelectionListWidget languagereload_init(LanguageOptionsScreen screen, MinecraftClient client) { | ||
throw new AssertionError(); | ||
} | ||
} |
29 changes: 21 additions & 8 deletions
29
src/main/java/jerozgen/languagereload/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
package jerozgen.languagereload.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import jerozgen.languagereload.access.ILanguage; | ||
import jerozgen.languagereload.access.ITranslationStorage; | ||
import jerozgen.languagereload.config.Config; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Language; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@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) { | ||
@WrapOperation(method = {"method_1485" /* Creative Inventory */, "method_53863" /* Recipe Book */}, | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getTooltip(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/client/item/TooltipContext;)Ljava/util/List;")) | ||
private static List<Text> addFallbackTranslationsToSearchTooltips(ItemStack instance, PlayerEntity player, TooltipContext context, Operation<List<Text>> operation) { | ||
var original = operation.call(instance, player, context); | ||
|
||
if (Config.getInstance() == null) return original; | ||
if (!Config.getInstance().multilingualItemSearch) return original; | ||
|
||
var translationStorage = ((ILanguage) Language.getInstance()).languagereload_getTranslationStorage(); | ||
if (translationStorage == null) return original; | ||
|
||
var stringBuilder = new StringBuilder(original); | ||
for (String fallbackCode : Config.getInstance().fallbacks) { | ||
var result = new ArrayList<>(original); | ||
for (var fallbackCode : Config.getInstance().fallbacks) { | ||
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(fallbackCode); | ||
stringBuilder.append('\n').append(text.getString()); | ||
operation.call(instance, player, context) | ||
.stream() | ||
.map(Text::getString) | ||
.map(Text::literal) | ||
.forEach(result::add); | ||
} | ||
|
||
((ITranslationStorage) translationStorage).languagereload_setTargetLanguage(null); | ||
return stringBuilder.toString(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters