simulatecraft.minecraft¶
simulatecraft.minecraft
¶
SimulateCraft Minecraft module.
Public API¶
from simulatecraft.minecraft import (
MinecraftEnvironment,
MinecraftBridge,
MinecraftObservation,
ALL_ACTIONS,
# individual actions:
Move, Jump, Sneak, LookAt,
MineBlock, PlaceBlock, UseItem, ActivateBlock,
EquipItem, DropItem, Craft,
Chat, Whisper,
NavigateTo, FollowEntity,
Wait,
)
ActivateBlock
¶
MineBlock
¶
NavigateTo
¶
UseItem
¶
BridgeError
¶
Bases: Exception
Raised when the bot process crashes or returns an error response.
MinecraftBridge
¶
MinecraftBridge(*, host: str = 'localhost', minecraft_port: int = 25565, username: str = 'SimBot', password: str = '', version: str | None = None, ipc_port: int = _DEFAULT_IPC_PORT, bot_script: str | Path | None = None, node_executable: str = 'node', connect_timeout: float = 30.0, request_timeout: float = 45.0, auth: str = 'offline')
Manages the Node.js Mineflayer subprocess and the JSON-RPC socket.
Source code in src/simulatecraft/minecraft/connection.py
connect
async
¶
Spawn the Node bot and wait until it signals it has joined the server.
Source code in src/simulatecraft/minecraft/connection.py
close
async
¶
Gracefully shut down the bot and the subprocess.
Source code in src/simulatecraft/minecraft/connection.py
call
async
¶
Send an RPC request and await its response.
Source code in src/simulatecraft/minecraft/connection.py
get_state
async
¶
perform_action
async
¶
Execute one action dict (matches Action.model_dump()) on the bot.
configure_presence
async
¶
configure_presence(*, x: float | None = None, y: float | None = None, z: float | None = None, gamemode: str | None = None) -> dict[str, Any]
Teleport after spawn via chat (RCON is preferred for reliability).
Source code in src/simulatecraft/minecraft/connection.py
AgentBotConfig
¶
AgentBotConfig(username: str, password: str = '', ipc_port: int = 25570, auth: str = 'offline', goal: str = '', spawn_x: float | None = None, spawn_y: float | None = None, spawn_z: float | None = None, persona: str = '')
Per-agent bot connection settings.
Source code in src/simulatecraft/minecraft/env.py
MinecraftEnvironment
¶
MinecraftEnvironment(*, server_host: str = 'localhost', server_port: int = 25565, version: str | None = None, bot_script: str | Path | None = None, node_executable: str = 'node', block_scan_radius: int = 6, entity_scan_radius: int = 16, chat_log_size: int = 20, connect_timeout: float = 30.0, request_timeout: float = 45.0)
Bases: Environment
Multi-agent Minecraft environment backed by Mineflayer bots.
Each registered agent maps to one bot subprocess. The environment
queries each bot's state for observe() and dispatches actions
back through the bridge in step().
Source code in src/simulatecraft/minecraft/env.py
add_bot
¶
add_bot(agent_id: str, *, username: str | None = None, password: str = '', ipc_port: int | None = None, auth: str = 'offline', goal: str = '', spawn_x: float | None = None, spawn_y: float | None = None, spawn_z: float | None = None, persona: str = '') -> None
Register an agent and configure its bot.
Call before connect(), or use :meth:spawn_bot to add one at runtime.
ipc_port defaults to the next free port starting at 25570.
Source code in src/simulatecraft/minecraft/env.py
connect
async
¶
Spawn all bots and wait for them to join the server.
Source code in src/simulatecraft/minecraft/env.py
spawn_bot
async
¶
spawn_bot(agent_id: str, *, username: str | None = None, password: str = '', auth: str = 'offline', goal: str = '', spawn_x: float | None = None, spawn_y: float | None = None, spawn_z: float | None = None, persona: str = '') -> None
Register and connect a bot while the environment is already running.
Source code in src/simulatecraft/minecraft/env.py
despawn_bot
async
¶
Disconnect one bot and forget its registration.
Source code in src/simulatecraft/minecraft/env.py
close
async
¶
prepare_tick
async
¶
Refresh bot observations before the runner asks each agent to decide.
observe
¶
observe(agent_id: str) -> MinecraftObservation
Return the latest cached observation for this agent.
Source code in src/simulatecraft/minecraft/env.py
step
async
¶
step(agent_id: str, action: Action) -> StepResult
Dispatch the action to the bot and wait for Mineflayer to finish it.
Source code in src/simulatecraft/minecraft/env.py
tick
¶
fetch_map
async
¶
Scan a top-down map tile for the viewer (also used by WS pan requests).
Source code in src/simulatecraft/minecraft/env.py
snapshot
¶
snapshot() -> Snapshot
Top-down Minecraft map (surface blocks) plus agent markers in world XZ.
Source code in src/simulatecraft/minecraft/env.py
BotStats
¶
Bases: BaseModel
Vital statistics of the bot.
ChatMessage
¶
Bases: BaseModel
One line from the Minecraft chat log.
InventoryItem
¶
Bases: BaseModel
One stack in the bot's inventory.
MinecraftObservation
¶
Bases: Observation
Full structured state snapshot handed to the agent brain each tick.
All fields have sensible defaults so partial observations work: the bridge can omit fields it hasn't queried yet and the brain still gets a valid model.
nearby_blocks
class-attribute
instance-attribute
¶
nearby_blocks: list[NearbyBlock] = Field(default_factory=list)
Blocks within the configured scan radius, sorted by distance.
nearby_entities
class-attribute
instance-attribute
¶
nearby_entities: list[NearbyEntity] = Field(default_factory=list)
Mobs and players the bot can detect.
chat_log
class-attribute
instance-attribute
¶
chat_log: list[ChatMessage] = Field(default_factory=list)
Last N chat messages (configurable in MinecraftEnvironment).
render
¶
Compact text summary injected into the LLM prompt.
Source code in src/simulatecraft/minecraft/observations.py
NearbyBlock
¶
Bases: BaseModel
A block within the scan radius.
NearbyEntity
¶
Bases: BaseModel
A mob or player the bot can see.
Vec3
¶
Bases: BaseModel
3-D float coordinate.