-
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
8e0a2aa
commit 4bc8d1f
Showing
11 changed files
with
304 additions
and
192 deletions.
There are no files selected for viewing
368 changes: 204 additions & 164 deletions
368
src/client/java/net/pedroricardo/HeadedRewrittenClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/client/java/net/pedroricardo/content/HeadOptionArgumentType.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,48 @@ | ||
package net.pedroricardo.content; | ||
|
||
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 io.wispforest.owo.config.Option; | ||
import net.minecraft.command.CommandSource; | ||
import net.minecraft.text.Text; | ||
import net.pedroricardo.HeadedRewritten; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class HeadOptionArgumentType implements ArgumentType<Option<Object>> { | ||
public static final DynamicCommandExceptionType INVALID_HEAD_OPTION_EXCEPTION = new DynamicCommandExceptionType((head) -> Text.translatable("argument." + HeadedRewritten.MOD_ID + ".head_option.invalid", head)); | ||
|
||
public static HeadOptionArgumentType head() { | ||
return new HeadOptionArgumentType(); | ||
} | ||
|
||
public static Option<Object> getHeadOption(CommandContext<?> context, String name) { | ||
return (Option<Object>) context.getArgument(name, Option.class); | ||
} | ||
|
||
@Override | ||
public Option<Object> parse(StringReader reader) throws CommandSyntaxException { | ||
String string = reader.readUnquotedString(); | ||
Option<Object> option = HeadedRewritten.CONFIG.optionForKey(new Option.Key(string)); | ||
if (option == null) { | ||
throw INVALID_HEAD_OPTION_EXCEPTION.create(string); | ||
} | ||
return option; | ||
} | ||
|
||
@Override | ||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) { | ||
Collection<String> collection = new ArrayList<>(); | ||
HeadedRewritten.CONFIG.allOptions().forEach((key, value) -> { | ||
if (key.asString().startsWith("headURLs.")) collection.add(key.asString()); | ||
}); | ||
return CommandSource.suggestMatching(collection, builder); | ||
} | ||
} |
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
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
Oops, something went wrong.