Skip to content

Task System en

ZoyLuo edited this page Jun 5, 2026 · 1 revision

Task System

Tasks are where AIBot actually "gets hands-on". Each task is a self-contained state machine: it takes parameters, drives itself forward, has its own timeout / stuck watchdog, and ends in COMPLETED or FAILED.

Design

  • Task / AbstractTask — the task interface and base class. Subclasses implement onStart / onTick / onAbort and finish via complete() / fail(reason).
  • TaskStateRUNNING · COMPLETED · FAILED, etc.
  • TaskManager — one active task per bot; handles assign / abort / tickAll.
  • BotTickCoordinator — the per-tick scheduler: safety net first, then Goal Engine / task progress, then idle coordination. See Safety Net.

Two iron rules

G1 — self-contained tasks. A task never assigns sub-tasks; it calls shared primitives (BlockMiner, DigNav, ActionPack, HarvestCore). No "state machine inside a state machine" fighting for control.

G2 — main-thread execution. All task logic runs on the server main thread for thread-safe world access.

Watchdogs & isWaiting()

Stationary tasks (mining, descending — the bot barely moves) override isWaiting() to return true, telling the global StuckWatcher "I'm working, not stuck". They rely on their own NO_PROGRESS / timeout watchdog instead — avoiding false kills by the coarse "position/progress unchanged = stuck" monitor.

Task catalog

The task package has 44 classes — about 30 concrete task state machines plus the base class, manager, coordinators and watchdogs.

🧭 Movement

Task Description
MoveTask Pathfind to a coordinate; falls back to dig-through when blocked (safely bails on water / attack)
FollowTask Follow a player
GuardTask Guard a point / person

⛏️ Mining

Task Description
MineTask Mine an exposed target block
OreDigTask Targeted ore mining, with prospecting + vein clearing
StripMineTask Strip mining
DescendToYTask Staircase-descend to a target Y
DigDownTask Staircase downward mining (never straight down)

🌾 Gathering / farming

Task Description
GatherQuotaTask Gather to a quota, with long-range tree prospecting + roaming
ForageTask Forage
FarmTask Plant / harvest crops
BreedTask Breed animals
FishTask Fish

🔨 Crafting

Task Description
CraftTask Craft (expands by actual materials, e.g. any-log → planks)
SmeltTask Furnace smelting (with fuel fetch / walk-to-furnace fallback)

⚔️ Combat / survival

Task Description
CombatTask (+CombatCore) Melee with line-of-sight checks
HuntTask Hunt for meat
EvadeTask Retreat / flee
EatTask Eat
SleepTask Sleep
LightAreaTask Torch an area
EmergencyShelterTask Emergency wall-up

🏗️ Building / logistics

Task Description
BuildTask Build from a blueprint
PlaceStationsTask Place workstations
ContainerTask Container deposit / withdraw
StockpileTask Stockpile & organize
ResupplyTask Resupply
TradeTask Villager trading
HoldTask Stand by

🛡️ Coordination & guards (not tasks)

TaskManager · BotTickCoordinator · StuckWatcher · DangerWatcher · NavSafetyNet — see Safety Net.


Further reading: Goal Engine (who dispatches these) · Safety Net (who backstops) · Architecture

Clone this wiki locally