Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

  • Author

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 by squidlex

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?

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.

  • Author
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.

I misunderstood the problem.  I am not sure, then.

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.

  • Author
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 :)

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 by poopoodice

  • Author
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! :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.