Skip to content

endorh/smart-completion

Repository files navigation

Smart Completion Mod

Minecraft: 1.16 - 1.21.1 Mod Loader: [Neo]Forge Mod Loader: Fabric Side: Client License Curse Forge Join the Discord

Smart Completion for Minecraft

Client-side mod that provides better autocompletion suggestions for Minecraft commands.

Note

You're on the v2 branch of the mod, for Minecraft 1.20.3+

Download

You can download the mod from CurseForge.

Usage

To type a command/argument made up of several words, type only a few initials of each of its words.

For example, if you want to type /gamerule doDaylightCycle true, you could type:

  • gr, which expands as [g]ame[r]ule
  • dc or ddc, which expand as [d]o(D)aylight[C]ycle
  • t, which expands as true

gamerule doDaylightCycle true

Keyboard Shortcuts

In addition of <Tab>, you may also use <Ctrl>+<Space> to accept a suggestion, which will automatically insert a space so you can start typing the next argument.

Note

This is definitely an intentional feature and not the fruit of me being too lazy to suppress the Space key event from being handled also by the input bar :)

Additionally, if the current command is known to be invalid (the text is red), pressing <Enter> will accept the selected suggestion, if any, rather than attempting to execute an invalid command.

By default, accepting a suggestion with <Ctrl>+<Space> or by using the middle button to click it will also erase the remaining text after the cursor, if you decide to edit an earlier argument at some point. This behavior can be configured per key/mouse button.

Disambiguating Suggestions

To disambiguate between suggestions, you may need to type more than one letter per word.

For example, to type fireDamage instead of fallDamage, which appears first when typing fd, you may type fid.

fireDamage

In general, it's way faster to type a few more letters to get the suggestion you want in front of the list rather than using the arrows/cycling with <Tab> to select it, as typing can build muscle memory.

Over time you will become used to the minimum number of letters you need to type the commands you frequently use, and typing them will feel like a breeze.

Browsing Suggestions

Since the words you type don't need to be at the start of the name you're typing, you may discover way more useful suggestions compared to how Minecraft suggestions usually work.

For example, if you type /give @p wood, you'll see suggestions for all items that contain a word that starts with wood.

/give @p wood

Additionally, if your query doesn't match any of the initials of a suggestion, it will also look anywhere within suggestions to provide weak matches. This is helpful when you don't know exactly what you're looking for.

Suggestion Style

Suggestions are highlighted according to the styles defined in the style.json file, which can be overridden by resource packs (see wiki).

By default, matches inside a suggestion are highlighted in blue. Alternative matches for a query part ([d]o(D)aylight[C]ycle), weak matches and unexpected server suggestions are all highlighted in dark aqua.

In addition, if a suggestion starts with a prefix of words, followed by a colon, (i.e., a resource location namespace), it will be highlighted in dark gray unless matched.

Extra Features

This mod also inverts by default the order of suggestions, so the most relevant suggestion is the closest one to the input bar.

If you find this too confusing, you may disable it with the following command:

/smartcompletion invert_suggestion_order false

Tip

Since you're using this mod, you could just type /sc, <Ctrl>+<Space>, iso, <Ctrl>+<Space>, f and <Enter> twice.

How does it work

This mod is purely client-side. To provide better completions for a command node we send two/three requests asking for suggestions to the server:

  • The one Vanilla would usually send, informed
  • One without the last partially typed argument, arg-blind
  • Optionally, one without the last partially typed word if the last argument node consists of several words (e.g., some World Edit commands), word blind

We then rely on the server replying with all unfiltered relevant suggestions to the blind requests.

Once the lists of suggestions arrive, in whichever order, they're combined, filtered and sorted them, according to the strategies described below, and, once sorted, we update the displayed suggestions.

In addition, since, while typing a single command, it is unlikely that the results for the blind requests will change, we may cache these requests.

World Edit Commands with cache enabled World Edit Commands with cache disabled

Tip

The behavior of the query cache can be configured with the /smartcompletion command. The default configuration is volatile (resets whenever you start typing a fresh command), and shouldn't cause any trouble.

If the server replies with suggestions for the informed request that were not matched by our filtering on the blind lists, they will be suggested after any other matched suggestions, highlighted with a different color (dark aqua by default).

This implementation should work well with any custom commands, added by either mods or datapacks.

Matching

Suggestions are matched to your partially typed arguments using two different approaches:

  • A smart match between segments of your query and the initials of parts of the suggestion (gr matches [g]ame[r]ule)
  • A weak search for each part of your query within the suggestion, in order (lock on matches b(lock)Explosi(on)DropDecay)

A suggestion will be shown if any of these approaches matches it, but smart matches will be shown first.

Both approaches are case-insensitive.

Word Splitting

We split words at any non-alphabetic character, as well as at camelCase words.

In addition, if a command cannot be split in this way, we will assume it's written in flatcase (like most Minecraft commands), and attempt to split it using a list of known words.

Tip

This list of words is defined by the flatcase_splitting.json file, and can be overridden by resource packs (see wiki). By default, it contains words used by Minecraft, Forge, Fabric and WorldEdit commands, as well as a few more.

Suggestion Sorting

Suggestions are sorted according to heuristics designed to fit a few use cases, which can be found in the tests.

Summarized, we use the following criteria to sort suggestions, in order:

  • suggestions targeting a position closer to the cursor are shown first (/give @p chest suggests [ before minecart_chest)
  • smart matches > weak matches > unexpected server suggestions ([d]o(D)aylight[C]ycle > sen(dC)ommandFeedback)
  • significant matches beyond some thresholds are shown first ([app]le > [a]cacia_[p]ressure_[p]late)
  • more part matches > less part matches ([d]o[I]nsomnia > [di]sableRaids)
  • matches where a single query part could've matched more than one suggestion part are sorted first ([d]o(D)aylight[C]ycle > [d]oWeather[C]ycle)
  • less suggestion parts > more suggestion parts ([d]o[I]nsomnia > [d]o[I]mmediateRespawn)
  • earlier matched parts > later matched parts ([g]ame[m]ode > default[g]ame[m]ode)
  • shorter suggestions > longer suggestions ([t]p > [t]ell)
  • original order from the server (usually alphabetic) ([f]all[D]amage > [f]ire[D]amage)