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

So I want to create a command to teleport between dimensions, for testing, but when I try to run it, the game says

"Unknown Command"
"...dimension_name_here <--[HERE]"
And I also tried using breakpoints but they didn't trigger whatsoever??

Command Class:
 

public class TeleportDimensionCommand {
    public static void register(CommandDispatcher<CommandSource> dispatcher) {
        LiteralArgumentBuilder<CommandSource> builder = Commands.literal("teleport_dimension").requires(source -> source.hasPermissionLevel(2));
        builder.then(Commands.argument("dimension", DimensionArgument.getDimension()));
        builder.executes(TeleportDimensionCommand::teleport); //Only breakpoint which triggered
        LiteralCommandNode<CommandSource> teleport_dimension = dispatcher.register(builder);
        dispatcher.register(Commands.literal("tp_dim").requires(source -> source.hasPermissionLevel(2)).redirect(teleport_dimension));
    }

    private static int teleport(CommandContext<CommandSource> context) {
        ServerPlayerEntity player;
        try {
            player = context.getSource().asPlayer(); //Put a breakpoint here..
            player.sendMessage(new StringTextComponent("Attempting teleport...")); //When I didn't put any arguments, this popped up in chat
        } catch (CommandSyntaxException e) {
            Main.getLogger().error(Markers.ERROR, "Could not get player from source");
            e.printStackTrace();
            return 0; //Also tried a breakpoint here
        }
        if(player.changeDimension(DimensionArgument.getDimensionArgument(context, "dimension")) == null) {
            Main.getLogger().error(Markers.ERROR, "Could not teleport player"); //Put a breakpoint here
            player.sendMessage(new StringTextComponent("Could not teleport"));
        } else {
            player.sendMessage(new StringTextComponent("Teleported!")); //Put a breakpoint here
        }
        return 1;
    }
}

In my main class:

package sdt.undergroundadditions;

//Imports here...

@Mod("undergroundadditions")
public class Main {
    public Main() {
      	//Some more code here..
        IEventBus forge = MinecraftForge.EVENT_BUS;

        //Adding listeners here...
        forge.addListener(this::serverStarting);
    }
  	//Some more methods in between here
    private void serverStarting(FMLServerStartingEvent event) {
        TeleportDimensionCommand.register(event.getCommandDispatcher());
        logger.info(Markers.SERVER_STARTING, "Initialized server starting events");
    }
}

And, there's no error in the logs too. What's wrong?

Edited by MyRedAlien43

On 3/22/2020 at 5:14 PM, MyRedAlien43 said:

And I also tried using breakpoints but they didn't trigger whatsoever??

Did you launch the project in debug mode? I don't know how intellij does it, but I know with eclipse you have to run the project in debug mode, not normal run, to get breakpoints to work. If it still doesn't break, set a breakpoint somewhere you KNOW the code is reaching, just to make sure it's debugging properly.

Beyond that not sure about  commands, not something I've messed with yet, but if you can get debug to work I'm sure that'll help!

  • Author
2 minutes ago, Ugdhar said:

Did you launch the project in debug mode? I don't know how intellij does it, but I know with eclipse you have to run the project in debug mode, not normal run, to get breakpoints to work. If it still doesn't break, set a breakpoint somewhere you KNOW the code is reaching, just to make sure it's debugging properly.

Beyond that not sure about  commands, not something I've messed with yet, but if you can get debug to work I'm sure that'll help!

Yes I did press debug mode... Let me just use another breakpoint somewhere..

Edited by MyRedAlien43
improper grammar!

  • Author

Okay, I added 2 more breakpoints, and the only one that triggered was the "executes" line. I will now edit the post to mark where I put the breakpoints

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.