Skip to content

Commit

Permalink
/spawnparticle now has suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Mar 26, 2024
1 parent 7a32feb commit 9920970
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.pedroricardo.commander.content.arguments;

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.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.core.sound.SoundCategory;
import net.pedroricardo.commander.CommanderHelper;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

public class ParticleArgumentType implements ArgumentType<String> {
private static final List<String> EXAMPLES = Arrays.asList("smoke", "bubble", "explode");
private static final List<String> SUGGESTIONS = Arrays.asList(
"bubble",
"smoke",
"note",
"portal",
"explode",
"flame",
"blueflame",
"soulflame",
"lava",
"footstep",
"splash",
"largesmoke",
"reddust",
"item",
"block",
"snowshovel",
"heart",
"slimechunk",
"fireflyGreen",
"fireflyBlue",
"fireflyOrange",
"fireflyRed",
"arrowtrail",
"fallingleaf",
"boatbreak"
);

public static ArgumentType<String> particle() {
return new ParticleArgumentType();
}

@Override
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
String remaining = builder.getRemainingLowerCase();
for (String string : SUGGESTIONS) {
Optional<String> optional = CommanderHelper.getStringToSuggest(string, remaining);
optional.ifPresent(builder::suggest);
}
return builder.buildFuture();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
Expand All @@ -13,6 +12,7 @@
import net.minecraft.core.world.Dimension;
import net.pedroricardo.commander.content.CommanderCommandSource;
import net.pedroricardo.commander.content.arguments.DimensionArgumentType;
import net.pedroricardo.commander.content.arguments.ParticleArgumentType;
import net.pedroricardo.commander.content.arguments.PositionArgumentType;
import net.pedroricardo.commander.content.arguments.Vec3dArgumentType;
import net.pedroricardo.commander.content.helpers.DoublePos;
Expand All @@ -21,7 +21,7 @@
public class SpawnParticleCommand {
public static void register(CommandDispatcher<CommanderCommandSource> dispatcher) {
CommandNode<CommanderCommandSource> command = dispatcher.register(LiteralArgumentBuilder.<CommanderCommandSource>literal("spawnparticle")
.then(RequiredArgumentBuilder.<CommanderCommandSource, String>argument("particle", StringArgumentType.word())
.then(RequiredArgumentBuilder.<CommanderCommandSource, String>argument("particle", ParticleArgumentType.particle())
.then(RequiredArgumentBuilder.<CommanderCommandSource, DoublePos>argument("position", PositionArgumentType.pos())
.executes(c -> {
execute(c, c.getArgument("particle", String.class), c.getArgument("position", DoublePos.class), Vec3d.createVector(0.0, 0.0, 0.0), null, null);
Expand Down

0 comments on commit 9920970

Please sign in to comment.