use of com.mojang.brigadier.builder.LiteralArgumentBuilder in project MinecraftForge by MinecraftForge.
the class ClientCommandTest method init.
private void init(RegisterClientCommandsEvent event) {
event.getDispatcher().register(Commands.literal("clientcommandtest").then(Commands.literal("rawsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests((c, b) -> SharedSuggestionProvider.suggestResource(ForgeRegistries.BLOCKS.getKeys(), b)).executes(this::testCommand))).then(Commands.literal("registeredsuggest").then(Commands.argument("block", ResourceLocationArgument.id()).suggests(SuggestionProviders.AVAILABLE_BIOMES).executes(this::testCommand))).then(Commands.literal("server").executes((context) -> {
context.getSource().getServer();
context.getSource().sendSuccess(new TextComponent("Successfully called getServer should have errored"), false);
return 1;
})).then(Commands.literal("level").executes((context) -> {
context.getSource().getLevel();
context.getSource().sendSuccess(new TextComponent("Successfully called getLevel should have errored"), false);
return 1;
})).then(Commands.literal("get_objective").then(Commands.argument("objective", ObjectiveArgument.objective()).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Regular: ").append(ObjectiveArgument.getObjective(context, "objective").getFormattedDisplayName()), false);
return 1;
}))).then(Commands.literal("get_advancement").then(Commands.argument("advancement", ResourceLocationArgument.id()).executes((context) -> {
context.getSource().sendSuccess(ResourceLocationArgument.getAdvancement(context, "advancement").getChatComponent(), false);
return 1;
}))).then(Commands.literal("get_recipe").then(Commands.argument("recipe", ResourceLocationArgument.id()).executes((context) -> {
context.getSource().sendSuccess(ResourceLocationArgument.getRecipe(context, "recipe").getResultItem().getDisplayName(), false);
return 1;
}))).then(Commands.literal("get_team").then(Commands.argument("team", TeamArgument.team()).executes((context) -> {
context.getSource().sendSuccess(TeamArgument.getTeam(context, "team").getFormattedDisplayName(), false);
return 1;
}))).then(Commands.literal("get_loaded_blockpos").then(Commands.argument("blockpos", BlockPosArgument.blockPos()).executes((context) -> {
context.getSource().sendSuccess(new TextComponent(BlockPosArgument.getLoadedBlockPos(context, "blockpos").toString()), false);
return 1;
}))).then(Commands.literal("requires").requires((source) -> false).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Executed command"), false);
return 1;
})));
// Used for testing that client command redirects can only be used with client commands
LiteralArgumentBuilder<CommandSourceStack> fork = Commands.literal("clientcommandfork");
fork.fork(event.getDispatcher().getRoot(), (context) -> List.of(context.getSource(), context.getSource())).executes((context) -> {
context.getSource().sendSuccess(new TextComponent("Executing forked command"), false);
return 1;
});
event.getDispatcher().register(fork);
}
Aggregations