Module command

Module command 

Source
Expand description

Functions for generating Minecraft commands that produce LogEvents.

LogEvents are only produced when the output of a command is written to Minecraft’s log file. For this to happen a number of preconditions have to be met:

  1. The command has to be executed by a player, command block or command block minecart. The output of a command executed by a mcfunction is never logged.
  2. The gamerule logAdminCommands has to be true. If the command block is executed by a command block or command block minecart then the gamerule commandBlockOutput also has to be true.

§Set Gamerules appropriately for Logging

It is typically not a good idea to enable the gamerule commandBlockOutput for longer than neccessary. The reason for this is that the output of commands is also written to the chat when the gamerule sendCommandFeedback is enabled. This will likely annoy players as it makes the chat unusable and causes it to take up a big part of the screen, even when only a single command logs it’s output every game tick. So whenever commandBlockOutput is enabled, sendCommandFeedback should be disabled. But sendCommandFeedback should not be disabled for longer than neccessary, because without it players will not get any output from commands they execute.

Ideally whenever the output of one or more commands should be logged, the three gamerules should first be set to enable logging without spamming the chat and after the commands are executed, the gamerules should be reset to their previous values to preserve the world configuration. This can be done with enable_logging_command and reset_logging_command.

§Logging Command Output from Minecraft Function Files

Minect offers two ways to work around the limitation of mcfunction files. To log the output of a command from a mcfunction file you can either use logged_block_commands or a logged_cart_command.

§Common Commands with useful Output

Minect offers a few functions to generate commands commonly used to retrieve information from Minecraft. Their output can then be parsed into predefined structs:

Structs§

AddTagOutput
The output of an add_tag_command. This can be parsed from a LogEvent::output.
QueryScoreboardOutput
The output of a query_scoreboard_command. This can be parsed from LogEvent::output.
SummonNamedEntityOutput
The output of a summon_named_entity_command. This can be parsed from a LogEvent::output.

Functions§

add_tag_command
Generates a Minecraft command that adds the given tag to the given entity.
enable_logging_command
Generates a Minecraft command that ensures LogEvents are created for all commands until a reset_logging_command is executed. These two commands are executed automatically by execute_commands if enable_logging_automatically is true (which is the default).
json_named_logged_block_command
See json_named_logged_block_commands. Must be preceded by a prepare_logged_block_command.
json_named_logged_block_commands
The same as named_logged_block_commands, but the name of the command block is given as a JSON text component.
json_named_logged_cart_command
The same as named_logged_cart_command, but the name of the command block minecart is given as a JSON text component.
logged_block_command
See logged_block_commands. Must be preceded by a prepare_logged_block_command.
logged_block_commands
Generates two Minecraft commands that cause the given command to be executed from a command block. This can be used to log the output of a command when running in a mcfunction.
logged_cart_command
Generates a Minecraft command that causes the given command to be executed from a command block minecart. This can be used to log the output of a command when running in a mcfunction.
named_logged_block_command
See named_logged_block_commands. Must be preceded by a prepare_logged_block_command.
named_logged_block_commands
The same as logged_block_commands, but also defines the name of the command block to allow easy filtering of LogEvents with MinecraftConnection::add_named_listener or LogObserver::add_named_listener.
named_logged_cart_command
The same as logged_cart_command, but also defines the name of the command block minecart to allow easy filtering of LogEvents with MinecraftConnection::add_named_listener or LogObserver::add_named_listener.
prepare_logged_block_command
Generates a Minecraft command that prepares the next logged_block_command, named_logged_block_command or json_named_logged_block_command.
query_scoreboard_command
Generates a Minecraft command that queries the score of entity in scoreboard.
reset_logging_command
Generates a Minecraft command that restores the logging gamerules to their values before the last enable_logging_command was executed.
summon_named_entity_command
Generates a Minecraft command that summons an area effect cloud with the given name.