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

How can I register local commands for a logical client side-only mod? I want to access these commands when for example playing on a server. However it seems the commands are first searched on the server and of course it fails when none is found.

i can see a part of the commands logic in CommandSuggestionHelper::updateCommandInfo(). This is called when I input a string in the command and seems to generate the suggestions by making a request to the server. And ChatScreen::keyPressed() calls sendMessage() which contains a comment

Quote

//if (net.minecraftforge.client.ClientCommandHandler.instance.executeCommand(mc.player, msg) != 0) return; //Forge: TODO Client command re-write

It looks like it might not be yet implemented. So is this possible? I am using version 1.16.5 - 36.1.0.

 

What I've tried (taken from MinecraftByExample)

public class TestCommand {
	public static void register(CommandDispatcher<CommandSource> dispatcher) {
		LiteralArgumentBuilder<CommandSource> mbequoteCommand = Commands.literal("mbequote")
				.then(Commands.literal("python")
						.executes(commandContext -> sendMessage(commandContext, QuoteSource.MONTY_PYTHON.getQuote())))
				.then(Commands.literal("blues")
						.executes(commandContext -> sendMessage(commandContext, QuoteSource.BLUES_BROTHERS.getQuote())))
				.then(Commands.literal("yogi")
						.then(Commands.literal("bear").executes(
								commandContext -> sendMessage(commandContext, QuoteSource.YOGI_BEAR.getQuote())))
						.then(Commands.literal("miaow").executes(
								commandContext -> sendMessage(commandContext, QuoteSource.YOGI_BERRA.getQuote())))
						.executes(commandContext -> sendMessage(commandContext, "Which Yogi do you mean?"))
				);
		dispatcher.register(mbequoteCommand);
	}

	static int sendMessage(CommandContext<CommandSource> commandContext, String message) throws CommandSyntaxException {
		TranslationTextComponent finalText = new TranslationTextComponent("chat.type.announcement",
				commandContext.getSource().getDisplayName(), new StringTextComponent(message));

		Entity entity = commandContext.getSource().getEntity();
		if (entity != null) {
			commandContext.getSource().getServer().getPlayerList().broadcastMessage(finalText, ChatType.CHAT,
					entity.getUUID());
			// func_232641_a_ is sendMessage()
		} else {
			commandContext.getSource().getServer().getPlayerList().broadcastMessage(finalText, ChatType.SYSTEM,
					Util.NIL_UUID);
		}
		return 1;
	}

	enum QuoteSource {
		MONTY_PYTHON(new String[] { "Nobody expects the Spanish Inquisition!",
				"What sad times are these when passing ruffians can say 'Ni' at will to old ladies.",
				"That's the machine that goes 'ping'.", "Have you got anything without spam?",
				"We interrupt this program to annoy you and make things generally more irritating.",
				"My brain hurts!" }),
		YOGI_BERRA(new String[] { "When you come to a fork in the road... take it.", "It ain't over till it's over.",
				"The future ain't what it used to be.", "If the world was perfect, it wouldn't be." }),
		YOGI_BEAR(new String[] { "I'm smarter than the average bear." }),
		BLUES_BROTHERS(new String[] { "Four fried chickens and a Coke, please.",
				"It's 106 miles to Chicago, we've got a full tank, half pack of cigarettes, it's dark out, and we're wearing sunglasses. Hit it.",
				"Are you the police?  No ma'am, we're musicians." });

		public String getQuote() {
			return quotes[new Random().nextInt(quotes.length)];
		}

		QuoteSource(String[] quotes) {
			this.quotes = quotes;
		}

		private String[] quotes;
	}
}

This command works on local multiplayer environment but not when connected to a dedicated/external server (meaning the server gets the request and replies with command not found)

Edited by Antonii
Detailed the issue

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.