Crate minect

Source
Expand description

Minect is a library that allows a Rust program to connect to a running Minecraft instance without requiring any Minecraft mods.

Using Minect a Rust program can execute commands in Minecraft and listen for command output. This way a Rust program can control or be controlled by Minecraft.

The connection requires a building in Minecraft which continuously loads structure files that contain commands generated by the Rust program. Listening for their output works by polling Minecraft’s log file.

§Example

let identifier = "MyProgram";
let world_dir = "C:/Users/Herobrine/AppData/Roaming/.minecraft/saves/New World";
let mut connection = MinecraftConnection::builder(identifier, world_dir).build();

println!("If you are connecting for the first time please execute /reload in Minecraft.");
connection.connect().await?;

let events = connection.add_listener();

connection.execute_commands([
  Command::new("scoreboard objectives add example dummy"),
  Command::new("scoreboard players set Herobrine example 42"),
  Command::new(query_scoreboard_command("Herobrine", "example")),
])?;

let output = events
  .filter_map(|event| event.output.parse::<QueryScoreboardOutput>().ok())
  .next()
  .await
  .expect("Minecraft connection was closed unexpectedly");

println!("{}'s score is {}", output.entity, output.score);

Modules§

command
Functions for generating Minecraft commands that produce LogEvents.
log
Observing Minecraft’s log file.

Structs§

Command
A Command can be passed to MinecraftConnection::execute_commands and contains a Minecraft command to execute and optionally a custom name.
ConnectError
The error returned from MinecraftConnection::connect.
ExecuteCommandsError
The error returned from MinecraftConnection::execute_commands.
MinecraftConnection
A connection to Minecraft that can execute commands in Minecraft and listen for command output.
MinecraftConnectionBuilder
A builder to create a MinecraftConnection is obtained via MinecraftConnection::builder.