Skip to content

These docs were made completely by AI, so they might be right, or wrong, you'll need to test them yourself. This was made for a easier understanding of everything. So use at your own risk. If anything is wrong, please don't hurt to make a PR on the page you have a problem with. ON GITHUB

Commands

MinecraftConsoles has a command system based on the 4J Studios console edition architecture. Commands use a binary packet-based dispatch instead of the text-parsing approach from Java Edition.

File: Minecraft.World/Command.h, .cpp

All commands extend the abstract Command class.

class Command
{
public:
virtual EGameCommand getId() = 0;
virtual int getPermissionLevel();
virtual void execute(shared_ptr<CommandSender> source, byteArray commandData) = 0;
virtual bool canExecute(shared_ptr<CommandSender> source);
static void logAdminAction(...);
};

Permission levels:

LevelConstantExamples
0LEVEL_ALLhelp, emote
1LEVEL_MODERATORSmute
2LEVEL_GAMEMASTERSseed, tp, give
3LEVEL_ADMINSwhitelist, ban
4LEVEL_OWNERSstop, save-all

Unlike Java Edition, commands receive byteArray commandData (a binary packet) instead of parsed string arguments. The default getPermissionLevel() returns LEVEL_GAMEMASTERS (2).

Two static logAdminAction() overloads handle command logging:

  • logAdminAction(source, messageType, message, customData, additionalMessage) for standard logging
  • logAdminAction(source, type, messageType, message, customData, additionalMessage) with an extra type parameter

These use ChatPacket::EChatPacketMessage for message categorization. A static AdminLogCommand *logger pointer is set via setLogger().

getPlayer(PlayerUID) returns a shared_ptr<ServerPlayer> for a given player UID, used by commands that target specific players.

File: Minecraft.World/CommandDispatcher.h, .cpp

Routes commands by their EGameCommand enum value.

class CommandDispatcher
{
unordered_map<EGameCommand, Command*> commandsById;
unordered_set<Command*> commands;
public:
int performCommand(shared_ptr<CommandSender> sender, EGameCommand command, byteArray commandData);
Command *addCommand(Command *command);
};

performCommand() checks canExecute() before running. If the sender doesn’t have permission, a red “You do not have permission” message is shown (except in content packages). Returns an integer status code.

addCommand() registers a command and returns it for chaining.

File: Minecraft.World/CommandsEnum.h

enum EGameCommand
{
eGameCommand_DefaultGameMode,
eGameCommand_Effect,
eGameCommand_EnchantItem,
eGameCommand_Experience,
eGameCommand_GameMode,
eGameCommand_Give,
eGameCommand_Kill,
eGameCommand_Time,
eGameCommand_ToggleDownfall,
eGameCommand_Teleport,
eGameCommand_COUNT
};

The eGameCommand_COUNT value is 10, meaning there are 10 registered command types.

File: Minecraft.World/CommandSender.h

The interface for anything that can send commands:

  • sendMessage(wstring message, EChatPacketMessage type, int customData, wstring additionalMessage) sends feedback
  • hasPermission(EGameCommand command) checks if the sender can use a command

CommandBlockEntity implements this interface directly.

These commands have native C++ implementations that are fully functional:

File: Minecraft.World/GameModeCommand.h, .cpp

Changes a player’s game mode. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_GameMode.

Includes getModeForString() to parse the mode argument from the binary packet.

File: Minecraft.World/DefaultGameModeCommand.h, .cpp

Sets the server’s default game mode. Extends GameModeCommand. Command ID: eGameCommand_DefaultGameMode. Permission level: LEVEL_GAMEMASTERS.

File: Minecraft.World/GiveItemCommand.h, .cpp

Gives items to players. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Give.

Has a static preparePacket() helper that builds a GameCommandPacket with item ID, amount, aux value, and optional NBT tag string.

File: Minecraft.World/KillCommand.h, .cpp

Kills the command sender. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Kill.

File: Minecraft.World/TimeCommand.h, .cpp

Sets or adds to the world time. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Time.

Methods: doSetTime() and doAddTime(). Has a static preparePacket() for toggling day/night via a packet.

File: Minecraft.World/ToggleDownfallCommand.h, .cpp

Toggles weather. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_ToggleDownfall.

File: Minecraft.World/EnchantItemCommand.h, .cpp

Enchants a player’s held item. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_EnchantItem.

Has a static preparePacket() that takes enchantment ID and level (default 1).

File: Minecraft.World/ExperienceCommand.h, .cpp

Grants experience to a player. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Experience.

File: Minecraft.Client/TeleportCommand.h, .cpp

Teleports players. Lives in Minecraft.Client rather than Minecraft.World, which is unusual. Command ID: eGameCommand_Teleport.

File: Minecraft.World/EffectCommand.h, .cpp

Applies or removes status effects from players. Permission level: LEVEL_GAMEMASTERS. Command ID: eGameCommand_Effect.

Several command files have complete Java source code in block comments. These are reference implementations that haven’t been ported to C++ yet. They exist only as #if 0 blocks or Java code in comments.

File: Minecraft.World/GameDifficultyCommand.h

Sets the server difficulty. Accepts peaceful/p, easy/e, normal/n, hard/h, or numeric 0-3. Tab-completion supported. Default permission level 2.

File: Minecraft.World/GameRuleCommand.h

Gets, sets, or lists game rules. With 0 args it lists all rules, with 1 arg it shows a rule value, with 2 args it sets a rule. Tab-completes rule names and true/false values. Default permission level 2.

File: Minecraft.World/ShowSeedCommand.h

Displays the world seed. Allows execution in singleplayer regardless of permission level (overrides canExecute()). Default permission level 2.

File: Minecraft.World/WeatherCommand.h

Sets weather to clear, rain, or thunder with an optional duration in seconds. Default duration is 300 to 600 seconds (randomly chosen). Tab-completes weather type names. Default permission level 2.

File: Minecraft.World/PlaySoundCommand.h

Plays a sound at a location for a specific player. Supports position, volume, pitch, and minimum volume arguments. Handles the case where the player is too far away by either sending the sound at reduced volume from a closer position or throwing an error. Default permission level 2.

File: Minecraft.World/SpreadPlayersCommand.h

Spreads players randomly across an area. Has a MAX_ITERATION_COUNT of 10,000 for the randomization algorithm. Default permission level 2.

File: Minecraft.World/SetPlayerTimeoutCommand.h

Sets the connection timeout for a player.

File: Minecraft.World/AdminLogCommand.h

The logging backend used by Command::logAdminAction().

File: Minecraft.World/GameRules.h, .cpp

While the GameRuleCommand itself isn’t ported, the GameRules class is implemented in C++. It stores game rules as typed values.

The inner GameRule class stores each rule as a wstring with cached bool, int, and double conversions.

Defined rules (4J converted from strings to integer constants):

Rule constantPurpose
RULE_DOFIRETICKFire spread
RULE_MOBGRIEFINGMob block destruction
RULE_KEEPINVENTORYKeep items on death
RULE_DOMOBSPAWNINGMob spawning
RULE_DOMOBLOOTMob item drops
RULE_DOTILEDROPSBlock item drops
RULE_COMMANDBLOCKOUTPUTCommand block output to chat
RULE_NATURAL_REGENERATIONNatural health regeneration
RULE_DAYLIGHTDaylight cycle

getBoolean(int rule) is the main query method.

File: Minecraft.World/EntitySelector.h, .cpp

Used throughout the command and entity systems for filtering entities.

class EntitySelector
{
public:
static const EntitySelector *ENTITY_STILL_ALIVE;
static const EntitySelector *CONTAINER_ENTITY_SELECTOR;
virtual bool matches(shared_ptr<Entity> entity) const = 0;
};

Built-in selectors:

ClassFilePurpose
AliveEntitySelectorEntitySelector.cppMatches entities that are still alive
ContainerEntitySelectorEntitySelector.cppMatches entities that are containers
MobCanWearArmourEntitySelectorEntitySelector.cppMatches mobs that can wear a specific armor item
HorseEntitySelectorEntityHorse.hMatches horse entities (for breeding)
LivingEntitySelectorWitherBoss.hMatches living entities (for Wither targeting)

The two static singleton instances (ENTITY_STILL_ALIVE, CONTAINER_ENTITY_SELECTOR) are used throughout the codebase for common filtering operations.

LCEMP has a smaller set of commands. The commands in MinecraftConsoles but not in the LCEMP base include:

  • /effect (stub)
  • /enchant
  • /xp (experience)
  • /defaultgamemode
  • All the Java-reference commands (difficulty, gamerule, seed, weather, playsound, spreadplayers)

Both codebases share the core commands: /gamemode, /give, /kill, /time, /toggledownfall, /tp.

MinecraftConsoles also adds the GameRules system, CommandBlock / CommandBlockEntity, and the EntitySelector system, none of which exist in LCEMP.