patterns have suggestions

This commit is contained in:
yrsegal@gmail.com 2022-04-08 17:52:25 -04:00
parent 352ed65dc4
commit 87abadb67d
2 changed files with 19 additions and 1 deletions

View file

@ -132,6 +132,14 @@ object PatternRegistry {
throw IllegalArgumentException("could not find a pattern for $opId")
}
/**
* Internal use only.
*/
@JvmStatic
fun getAllPerWorldPatternNames(): Set<ResourceLocation> {
return this.perWorldPatternLookup.keys.toSet()
}
/**
* Special handling of a pattern. Before checking any of the normal angle-signature based patterns,
* a given pattern is run by all of these special handlers patterns. If none of them return non-null,
@ -196,4 +204,4 @@ object PatternRegistry {
const val TAG_SAVED_DATA = "hex.per-world-patterns"
private const val TAG_OP_ID = "op_id"
private const val TAG_START_DIR = "start_dir"
}
}

View file

@ -5,11 +5,16 @@ import at.petrak.hexcasting.hexmath.HexPattern;
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 net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.ResourceLocationArgument;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import java.util.concurrent.CompletableFuture;
public class PatternResLocArgument extends ResourceLocationArgument {
private static final DynamicCommandExceptionType ERROR_UNKNOWN_PATTERN = new DynamicCommandExceptionType(
(errorer) ->
@ -20,6 +25,11 @@ public class PatternResLocArgument extends ResourceLocationArgument {
return new PatternResLocArgument();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return SharedSuggestionProvider.suggest(PatternRegistry.getAllPerWorldPatternNames().stream().map(Object::toString), builder);
}
public static HexPattern getPattern(
CommandContext<CommandSourceStack> ctx, String pName) throws CommandSyntaxException {
var targetId = ctx.getArgument(pName, ResourceLocation.class);