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:
- The command has to be executed by a player, command block or command block minecart. The
output of a command executed by a
mcfunctionis never logged. - The gamerule
logAdminCommandshas to betrue. If the command block is executed by a command block or command block minecart then the gamerulecommandBlockOutputalso has to betrue.
§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§
- AddTag
Output - The output of an add_tag_command. This can be parsed from a LogEvent::output.
- Query
Scoreboard Output - The output of a query_scoreboard_command. This can be parsed from LogEvent::output.
- Summon
Named Entity Output - 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
tagto the givenentity. - 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
entityinscoreboard. - 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.