simulatecraft.minecraft.env¶
simulatecraft.minecraft.env
¶
MinecraftEnvironment — bridges SimulateCraft's Environment interface to Mineflayer.
One MinecraftEnvironment manages one or more bots (one per registered agent).
Each agent gets its own MinecraftBridge connection to its own bot process,
so agents can be physically separate bots in the same Minecraft server.
Usage¶
env = MinecraftEnvironment(
server_host="localhost",
server_port=25565,
)
async with env:
env.register_agent("alex", username="Alex")
env.register_agent("bob", username="Bob")
runner = Runner(environment=env, config=RunnerConfig(tick_rate=1.0))
runner.add_agent(Agent(id="alex", brain=LLMBrain(...)))
runner.add_agent(Agent(id="bob", brain=LLMBrain(...)))
await runner.start()
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.