kyazuki Posted January 30, 2020 Posted January 30, 2020 (edited) The game shows my command by auto complete, so I think the game knows my command. However, system always shows "Unknown command". public class SetDistanceCommand { public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(Commands.literal("setdistance") .requires(source -> source.hasPermissionLevel(2)) .then(Commands.argument("blocks", IntegerArgumentType.integer())) .executes(context -> { context.getSource().sendFeedback(new TranslationTextComponent("commands.mymod.setdistance"), true); MyModConfig.distanceToNormal = IntegerArgumentType.getInteger(context, "blocks"); return 0; })); } } Edited July 30, 2020 by kyazuki Quote
T_VDP Posted May 5, 2020 Posted May 5, 2020 (edited) How do you register your command? Edited May 5, 2020 by T_VDP Quote
kyazuki Posted May 5, 2020 Author Posted May 5, 2020 This is it. @SubscribeEvent public static void onServerStart(FMLServerStartingEvent event) { SetDistanceCommand.register(event.getCommandDispatcher()); } Quote
T_VDP Posted May 5, 2020 Posted May 5, 2020 After looking at the vanilla code, I noticed the .executes() must follow the Commands.argument() immediately. Thus not when .then() already has been executed. Quote
TheGreyGhost Posted May 5, 2020 Posted May 5, 2020 Howdy The syntax of commands is tricky to get right. This working example might help explain it https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe45_commands -TGG Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.