Posted January 30, 20205 yr 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, 20205 yr by kyazuki
May 5, 20205 yr Author This is it. @SubscribeEvent public static void onServerStart(FMLServerStartingEvent event) { SetDistanceCommand.register(event.getCommandDispatcher()); }
May 5, 20205 yr After looking at the vanilla code, I noticed the .executes() must follow the Commands.argument() immediately. Thus not when .then() already has been executed.
May 5, 20205 yr 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
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.