squidlex Posted July 9, 2020 Share Posted July 9, 2020 I'm looking to update a command tree I made for 1.12 to 1.15.2. Obviously Commands have changed to the CommandDispatcher now, so does anybody know of any good/simple source code I could look at for a basic command tree? Thanks for your help! Quote Link to comment Share on other sites More sharing options...
squidlex Posted July 9, 2020 Author Share Posted July 9, 2020 (edited) Update: I'm definitely misunderstanding this. Here's my code: public class Command { public static void register(CommandDispatcher<CommandSource> dispatcher) { final LiteralArgumentBuilder<CommandSource> root = Commands.literal("commandtree"); root.then(Commands.literal("edit_a_float").then(Commands.argument("float", FloatArgumentType.floatArg()))).executes(source -> { return editPower(source.getSource(), source.getSource().asPlayer(), FloatArgumentType.getFloat(source, "float")); }).then(Commands.argument("player", EntityArgument.player())).executes(source -> { return editPower(source.getSource(), EntityArgument.getPlayer(source, "player"), FloatArgumentType.getFloat(source, "float")); }); root.then(Commands.literal("edit_a_cooldown").then(Commands.argument("ticks", IntegerArgumentType.integer()))).executes(source -> { return editCooldown(source.getSource(), source.getSource().asPlayer(), IntegerArgumentType.getInteger(source, "ticks")); }).then(Commands.argument("player", EntityArgument.player())).executes(source -> { return editCooldown(source.getSource(), EntityArgument.getPlayer(source, "player"), IntegerArgumentType.getInteger(source, "ticks")); }); dispatcher.register(root); } private static int editPower(CommandSource source, PlayerEntity player, float amount) { System.out.println("Adjusted power by " + amount + "!"); return 1; } private static int editCooldown(CommandSource source, PlayerEntity player, int ticks) { System.out.println("Adjusted cooldown by " + ticks + "!"); return 1; } } When entering my command, edit_a_float and edit_a_cooldown are recommended, but it also recommends usernames and all the @s. When typing in a command I get the message 'Unknown Command' or 'Incorrect argument for command'. Please could someone explain to me where I'm going wrong? Edited July 9, 2020 by squidlex Quote Link to comment Share on other sites More sharing options...
Draco18s Posted July 9, 2020 Share Posted July 9, 2020 Because that's how commands work. @p and not supplying a target means that it affects the player typing the command. But what if you wanted to affect a different player? Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
squidlex Posted July 9, 2020 Author Share Posted July 9, 2020 33 minutes ago, Draco18s said: Because that's how commands work. @p and not supplying a target means that it affects the player typing the command. But what if you wanted to affect a different player? Thanks for your reply, but I'm now seeing either I worded my question poorly or I don't quite understand your reply. It doesn't sugget @p or anything like that at all when I type /commandtree edit_a_float but it does when I type /commandtree. When I type /commandtree edit_a_float and then type anything after that it returns Unknown Command. Quote Link to comment Share on other sites More sharing options...
Draco18s Posted July 9, 2020 Share Posted July 9, 2020 I misunderstood the problem. I am not sure, then. 1 Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
squidlex Posted July 9, 2020 Author Share Posted July 9, 2020 6 minutes ago, Draco18s said: I misunderstood the problem. I am not sure, then. Not to worry, I appreciate the time you took to respond Quote Link to comment Share on other sites More sharing options...
poopoodice Posted July 9, 2020 Share Posted July 9, 2020 (edited) If my understanding is correct, .executes() needs to put inside the bracket of the .then (all "connected" action needs to do that)which should look like this root.then(Commands.literal("edit_a_float") .then(Commands.argument("float", FloatArgumentType.floatArg()) -> removed two brackets here .executes(source -> { return editPower(source.getSource(), source.getSource().asPlayer(), FloatArgumentType.getFloat(source, "float")); }))); -> added two brackets here Edited July 9, 2020 by poopoodice 1 Quote Link to comment Share on other sites More sharing options...
squidlex Posted July 9, 2020 Author Share Posted July 9, 2020 1 hour ago, poopoodice said: If my understanding is correct, .executes() needs to put inside the bracket of the .then (all "connected" action needs to do that)which should looks like this root.then(Commands.literal("edit_a_float") .then(Commands.argument("float", FloatArgumentType.floatArg()) -> removed two brackets here .executes(source -> { return editPower(source.getSource(), source.getSource().asPlayer(), FloatArgumentType.getFloat(source, "float")); }))); -> added two brackets here That was the problem! Thanks for spotting that, I'm really bad at spotting little errors like this. Thank you so much I can finally finish porting my mod! Quote Link to comment Share on other sites More sharing options...
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.