-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
f41bcc2
commit 196b3ac
Showing
4 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/org/auioc/mods/arnicalib/client/command/argument/LanguageInfoArgument.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,50 @@ | ||
package org.auioc.mods.arnicalib.client.command.argument; | ||
|
||
import java.util.SortedSet; | ||
import java.util.concurrent.CompletableFuture; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.arguments.ArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; | ||
import com.mojang.brigadier.suggestion.Suggestions; | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; | ||
import org.auioc.mods.arnicalib.ArnicaLib; | ||
import org.auioc.mods.arnicalib.utils.game.TextUtils; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.resources.language.LanguageInfo; | ||
import net.minecraft.commands.SharedSuggestionProvider; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class LanguageInfoArgument implements ArgumentType<LanguageInfo> { | ||
|
||
private static final DynamicCommandExceptionType UNKNOWN_CREATIVE_MODE_TAB = new DynamicCommandExceptionType( | ||
(langCode) -> TextUtils.I18nText(ArnicaLib.i18n("argument.language_info.unknown"), langCode) | ||
); | ||
|
||
public static LanguageInfoArgument languageInfo() { | ||
return new LanguageInfoArgument(); | ||
} | ||
|
||
@Override | ||
public LanguageInfo parse(StringReader reader) throws CommandSyntaxException { | ||
String langCode = reader.readString(); | ||
return getLanguages() | ||
.stream() | ||
.filter((langInfo) -> langInfo.getCode().equals(langCode)) | ||
.findAny() | ||
.orElseThrow(() -> UNKNOWN_CREATIVE_MODE_TAB.create(langCode)); | ||
} | ||
|
||
@Override | ||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { | ||
return SharedSuggestionProvider.suggest(getLanguages().stream().map(LanguageInfo::getCode), builder); | ||
} | ||
|
||
private static SortedSet<LanguageInfo> getLanguages() { | ||
return Minecraft.getInstance().getLanguageManager().getLanguages(); | ||
} | ||
|
||
} |
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