# Houses and bases

How bots build their houses, share a base with their faction and keep their stuff organized in chests.

import { AccordionItem, Accordions } from '@prosefly/astro-components';

Every bot wants a place to call home. Once it has its stone tools, building a small house becomes its top
priority. Over time that house becomes part of a **base**, a cluster of buildings it shares with its faction, with
chests full of everything they've gathered, an enchanting corner and a portal to the Nether. Some styles do it
differently. The [Turtler](/ai-players/guide/play-styles/#turtler) walls its base into a cobblestone
[fortress](/ai-players/guide/defenses/#the-fortress-wall), and the [Flanker](/ai-players/guide/play-styles/#flanker)
digs a [hidden base](#hidden-bases) into a hillside.

## A bot's house

Each bot designs its own house from what it has on hand, so no two bases look quite the same:

- 5×5 or 7×7 blocks, with walls three blocks high and a flat roof
- wooden plank walls when it has enough wood, cobblestone otherwise
- log columns at the corners when it has logs to spare
- glass windows on every side except the door's, when it can make glass
- a door made from the wood it holds, when that makes a door (six planks, a log counting for four). Otherwise it
  uses the wood of the nearest trees it knows, so a bot in a jungle hangs a jungle door.
- inside, a bed, a chest, a torch, a crafting table and a furnace (plus a brewing stand for styles that brew
  potions). From then on the crafting table is the bot's own. It crafts there and never picks it up, and a miner
  whose pickaxe breaks at dusk makes the next one on it at home.

### The bed comes within a day

A house without a bed isn't finished. A bot needs three wool of one color (the color it already holds most), so it
goes out for sheep. It tries the ones in sight first. If there are none, by day (until the early afternoon) it walks
through its roaming radius to where it last saw sheep, toward the nearest flock it remembers within 256 blocks, or
to spots around its house, looking around at each one. Sheep in sight by day put the bed ahead of the bot's mine
whatever its style, and three wool in hand put it ahead of its next tool, so the bed is made the day its wool is
had. A bot hunting for food with no bed takes the sheep in sight first, so its first flock gives it its bed with its
meat. Once it holds its iron pickaxe (and its shield, for a sword or axe style) and two iron ingots it can spare, it
makes shears first and shears the sheep, which live and regrow their wool. Otherwise it kills three. It keeps its
shears in hand afterwards, and every wool and string it holds while the house has no bed. A walk that finds no sheep
isn't tried again for a day. Where no sheep live, the bed comes from **string**: twelve string, from the spiders at
its door at dusk, the morning's leftover spiders or the cobwebs it cuts beside its mine, make four white wool in its
own crafting grid. Once the wool or the string, three planks and a table are held, the bed is made and placed as
soon as the bot is home, at any hour. A farming style that pens sheep shears its own pair for the wool
([Farming and animals](/ai-players/guide/farming/#sheep-and-the-bed)).

### The first house comes first

A bot treats its first house as part of surviving. As soon as a homeless bot holds a **stone pickaxe**, raising its
first house becomes its top priority, ahead of iron tools, armor and mining. That goes even for styles like the
Rusher or Flanker that normally care very little about building. Before it starts gathering materials, it checks
that a plain walk can reach the site. If no buildable ground exists within its roaming radius (say, on a tiny island
or steep cliff), it goes looking for a place to live by day, exploring outward in eight directions until it finds
suitable land. Before the walls rise it sows its first crop plot beside the site, which founds the base there
([the first plot](/ai-players/guide/farming/#the-crop-field)), and it clears the leaves standing in the roof's cells
from inside, so a tree's crown never hides a roof block. A half-built house is never dropped for another site while
it makes progress. Only a house that makes no progress three times running is given up. A miner (a style with a
mining strategy and a gear goal of iron or above) then puts its mine before the rest of its base: until it holds an
iron pickaxe, its storehouse and its fortifications count half.

### The quarry

The first house's stone comes from a **quarry** rather than a pit under the bot's feet. A homeless bot with a
pickaxe opens it two blocks out from the house's back wall (or from its flanks, then the door's side, when that
ground won't do). The quarry is a one-wide staircase going down and away from the house, lit at its bottom, then a
gallery along the bottom that never runs back under the house. Every block is cut from where the bot stands. It digs
until it holds the cobblestone the house lacks, then walks back up the stair and builds. Whatever extra it brought up
is kept or stored like any stockpile. The bot gives up on a quarry that meets water, lava or a drop near the top, or
whose next step it can't reach three times running, and gets its stone from elsewhere the usual way. Until the house
is built and furnished, the quarry counts as the bot's own works, so a bot digging in it is never "rescued" from it
as if trapped. A bot whose base already stands, or a village-side style building beside a village, gets its stone
the usual way too.

### Building on rough ground and repairing damage

Bots don't need a flat meadow to build:

- **Slopes and hillside dugouts:** they clear trees, bamboo and leaves, fill small dips (up to 3 blocks deep) and
  cut into slopes (spanning up to 4 blocks of height difference). The hillside rock stays standing as part of the
  back wall, so a house on a slope becomes a snug dugout.
- **Repairs after explosions:** when a creeper blows a hole in a bot's house, the bot fixes it instead of building a
  second house next door. As long as any part of the walls or roof still stands, it fills the crater under the floor
  and rebuilds the missing blocks in place (burrowing at night until the roof and walls are whole again).

## The base

The first house a bot finishes founds its base (or the first chest it stores into, or the crop plot it sows at the
house's site before the walls). Bots of the same [faction](/ai-players/guide/factions/) share a single base. Each one builds its own house there, next to the others, with its door facing the center. A bot
without a faction has a base all to itself.

As the base grows, so do its chests. When they start filling up, a bot builds a **storehouse**, a 5×7 building
with an aisle of chest spots. It starts with two chests and adds more as they fill. When every spot holds a
chest and they fill up again, the faction builds another storehouse.

Once bots bring shells home from [the End](/ai-players/guide/the-end/#shulker-shells-and-boxes), **shulker boxes**
stand in the storehouse too. Each bot of the faction keeps one box for its trips. Any extra box goes into an empty
chest slot before a new chest is made, placed facing up with the cell above it free so its lid opens. Shells beyond
the reserve are crafted into boxes (two shells and a chest) only while a slot is waiting for one.

Later on, the base gets a [farm, animal pen and nether wart bed](/ai-players/guide/farming/), an **enchanting
corner**, a [Nether portal](/ai-players/guide/nether/#building-the-portal) and, for play styles that care about
safety, [walls, lights, traps and golems](/ai-players/guide/defenses/).

## Hidden bases

A bot of the `hidden` base style (the shipped Flanker) doesn't build a house at all. It digs one into a hill
instead. Its site is a hillside within its roaming radius (at most 48 blocks) where the room, its tunnel and three
blocks of ground over the room are all natural stone, dirt or ore, with no sand or gravel to fall in. The ground
outside the tunnel's mouth has to be open and dry. With no such site in reach, it goes looking for one by day,
heading for the steepest ground it can see.

The house is a room five by five and three high inside, lit by a torch, with the bed, the chest, the crafting table
and the furnace. A door at the inner end of a one-wide tunnel three blocks long leads into it. The bot digs the
tunnel from outside and the room from the tunnel in, then closes the tunnel's mouth behind it with two blocks of
whatever it carries, so the hillside shows no hole. Every time it walks out or in, it opens the mouth, goes through
and seals it again behind itself.

Nothing of a hidden base stands in the open. It has no wall, yard, traps or golems, no farm plot, wart plot or pen,
and no enchanting corner. Its storehouse is a second room, seven by seven with ten chest spots, dug off a side wall
of the house behind a door. The base's portal is built like any other base's, and its mine starts outside the mouth
on open ground (the Flanker cave-mines anyway). An enemy only learns where such a base is by seeing a block of it
with nothing in between, which in practice means following the owner in. Walking past the hill teaches it nothing
([Raiding enemy bases](/ai-players/guide/raiding/#finding-the-enemy-base)).

## The enchanting corner and enchanting gear

Once a bot whose gear goal is diamond or netherite holds the diamond tools (pickaxe, sword and axe), it raises the
base's **enchanting corner** out in the yard. It never goes inside a house, since no house has room for a table plus
the one-block air gap the shelves need.

- It levels a 5×5 patch of the yard two blocks clear of every other building and places the **enchanting table**
  (two diamonds, four obsidian and a book) at its center. Around it, in a ring two blocks out, it leaves room for up
  to 15 bookshelves, with the middle of the side facing the base's center left open as the way in.
- The shelves come one at a time as the books come. A bookshelf takes six planks and three books, and a book takes
  three paper and a leather. The paper comes from sugar cane it cuts on riverbanks (above the root, so the cane grows
  back). The leather comes from a cow it hunts or from the chests, and the obsidian from a pour beside lava or from
  obsidian it finds with its diamond pickaxe. A faction has one corner, and every member may fill it.
- Any bot that knows an enchanting table (the corner's, or one you set down within 48 blocks of it) enchants its
  gear there (`enchant`). It uses the experience vanilla gives it for mining, smelting, fighting and fishing, once it
  has three lapis lazuli and a level high enough for the table's first offer (2 with no shelves, 4 with three, 10
  with all fifteen). The pieces go in a fixed order, one per run: its best sword, then the chestplate, leggings,
  helmet and boots it wears (taken off for the table and put back on), then its best pickaxe. Pieces already
  enchanted are skipped. It takes the highest offer its level and lapis afford (the third slot when the shelves and
  the level allow) and never re-rolls. Nothing else spends a bot's experience.
- While pieces wait at a known table, lapis becomes something to [mine](/ai-players/guide/mining/) for (four per
  waiting piece), and `stow` keeps that many in hand.

## The machine yard

A faction's machines from other mods (the [stations](/ai-players/reference/mod-integration/#stations-and-machine-recipes)
a plugin registers with a menu: a kiln, a press, a generator) stand in one place, the base's **machine yard**. It's
a 7×7 patch leveled beside the storehouse, inside the ring when one stands, with no wall or roof, an aisle through
the middle with a torch at each end, and room for four machines, one in each corner, each facing the aisle with the
cell in front of it kept clear.

A member that needs a machine for a plan while it's at the base places it in the yard's next free spot, and the base
records it. With no yard yet and a storehouse standing, it lays the yard out first. With every spot taken, away from
the base, or without a faction, the bot places its machine where it stands. Crafting tables, furnaces, brewing
stands and smithing tables never go to the yard.

Every member uses any machine of the yard. A load another member left in a machine is that member's: the bot never
empties or adds to it, and takes the next free machine or waits as it does for a busy furnace. A machine broken or
taken away frees its spot. The yard is a building of the base, so the ring, the moat, the light and the base's
protections cover it, and a raider can [carry its machines off](/ai-players/guide/raiding/#the-raid).

## Chests and storage

Bots are tidy:

- They remember every chest they've opened and what was in it, and look at it again whenever it's nearby.
- They bring their surplus home. When their pockets fill up, they cook any raw meat they're carrying in the base's
  furnace and keep 64 hunger points of their best food plus their active tools, weapons, armor, shield, torches and
  basics. Everything else gets stored, including outgrown wooden and stone tools once they hold a full iron or
  diamond set.
- They take from the chests when they need something. Before mining for iron, a bot checks whether there's some in
  storage already, takes what's there even when it's less than the plan needs (two ingots from the chest and one
  smelted, rather than three ore mined), and uses several chests if one isn't enough.
- At dusk, a bot within a few blocks of a base chest with room stows even a single stack, so the day's ingots and
  spare ore are in the chest before the night.
- A mining bot puts a chest at the top of its mine, with a spare pickaxe inside. Bots in
  [the Nether](/ai-players/guide/nether/#the-nether-camp) set up a **camp** with a 3×3 shelter and up to 8 chests
  beside their arrival portal, and haul the valuables home on the way back.
- A placed shulker box of the base counts as one of its chests, and the bot opens it with its own click like any
  other. It's never the innermost chest that holds the dragon egg, though, since a raider carries a box off whole.
  `/aiplayer info
  <bot> chests` lists it as `storehouse box`, `house box` and so on.
- The End's trophies (the dragon egg, the dragon head and any elytra beyond the one a flier keeps) go alone into the
  base's **innermost chest**, the one a raider walking in from the edge would open last.

### The carried box

A bot setting out on a trip from home (through a portal, to the End, on a raid) with no shulker box takes one from
the base's chests first. If there's none, it crafts one from two shells and a chest when the base holds them, and
with neither it goes without. When it's far from its base's chests (beyond 64 blocks of the anchor, or in another
dimension) with fewer than two free slots and no camp or mine chest with room nearby, it places the box beside it on
a standable floor (never on protected ground, by the End's void, or near a piglin). It opens the box with its own
click, moves in what `stow` would stow, least valuable first, then breaks the box and picks it up with everything
inside. What a carried box holds counts for nothing until it's emptied. It's lost with the box at death and found
again with it. Back home, `stow` empties the box first: the bot places it within reach of the chests, moves its
stacks out and stores them, then breaks it and picks it up. It keeps one empty box and stows any others. `info`
shows it as `box: 12/27 stacks`.

### A base notices thefts

A base keeps track of what its chests hold, so it notices when something goes missing. That covers a chest holding
fewer of an item than last time without any bot of the base having taken it, the storehouse's decoy being opened or
its TNT going off, and an enemy seen leaving the yard with something valuable in hand. The base writes the theft
down, along with the likeliest thief and its faction. If that faction is an enemy, the base's bots hunt the thief
and raid its base back. If it isn't (an operator helping itself, say), the theft is recorded and nothing happens.
See [the counter-raid](/ai-players/guide/raiding/#the-counter-raid).

## Bases are protected

Bots never dig into a building of any base, even an enemy's. They don't take its blocks as building material, and
they never build into another bot's house. A house under construction is off-limits too.

The one exception is a [raid](/ai-players/guide/raiding/) in progress, which frees four things for the raider:

- one fence post, gate or fortress door of the wall
- one floor block outside the buildings (where its TNT trap goes)
- the ground *under* the wall and the yard, for a tunnel (plus the one floor block under the chest it opens from
  below, which it puts back)
- the chests its faction recorded there, which it may open

Buildings and everything inside them are never dug otherwise, raid or no raid, and a protection mod that refuses
the raider is obeyed, the same as it is for you.

This protection is about how bots behave toward each other, though. A faction at war with yours may still send
raiders after your chests. See [Raiding enemy bases](/ai-players/guide/raiding/) for what they come for and how to
stop them. Nothing stops *you* from opening a bot base's chests or breaking its walls either, but do it while a base
bot is watching and you earn its faction's grudge ([offenses in the base](/ai-players/guide/combat/#offenses-in-the-base)).

## Custom buildings

Want bots to build *your* house design? A data pack can give a play style its own house and storehouse, built
from a structure block in creative mode. See [Data packs](/ai-players/reference/data-packs/#custom-buildings) for
how to make one.

## Play styles and homes

- Most play styles build a regular house wherever they settle.
- The **Boomer** settles next to a village instead. See [Villages and trading](/ai-players/guide/trading/).
- The **Turtler** walls its base in a cobblestone fortress. See [Base defenses](/ai-players/guide/defenses/#the-fortress-wall).
- The **Flanker** lives in a [hidden base](#hidden-bases) dug into a hill.
- A play style can also opt out of homes entirely, and its bots never build one.

## Technical details

<Accordions>
  <AccordionItem title="How the base grows">
    - The base is founded at the door of the first house a bot finishes, at the first chest it stores into, or at
      the first crop plot it sows beside the house's site.
    - Every later house of the faction goes up inside the base's bounds grown by 16 blocks, nearest the base's
      anchor, two blocks clear of every other building, with its door toward the anchor. Two homeless faction
      mates build their first houses side by side.
    - The house that founds a base is always 5×5. Later houses are 5×5 or 7×7, chosen from the bot's seed.
    - A house finished more than 24 blocks from a base that already has a house stays its bot's own and isn't
      added to the base (for example, an old house of a bot that joins a faction).
    - A storehouse is built when the base's chests have fewer than 54 free slots (two chests' worth). Only one
      storehouse is built at a time per faction.
  </AccordionItem>
  <AccordionItem title="What a bot keeps when it stores things">
    When storing, a bot first cooks any raw meat in its pockets at the base's furnace. Then it keeps:

    - its current tier's tools (stowing outgrown lower-tier tools once it holds a full sword, axe and pickaxe set of
      a higher tier, except one stone pickaxe if it has no spare yet), its weapons, shield and armor, its best hoe
      and its shears
    - up to 64 hunger points of cooked or farmed food
    - its stockpile targets' worth of logs, cobblestone, coal, sticks, torches, arrows and sugar cane (a miner also
      keeps its kit of 16 sticks, 8 planks, 8 torches and a crafting table to carry, plus 6 planks while it wants a
      shield)
    - every wool and string while its house has no bed, and three string, sixteen flint and sixteen feathers for a
      style with a bow
    - two ender pearls
    - four lapis for each piece waiting to be enchanted (every book, shelf and lapis for a style that raises the
      corner)
    - its style's target count of potions
    - its flint and steel and spare obsidian (for Nether travelers)
    - one water bucket (or the empty bucket), its boat, its bow, its fishing rod and the enchanted books fishing
      brings
    - two golden apples and its healing potions
    - a stack of bones and one of bone meal while a farm plot stands
    - saplings and seeds
    - the material of the last armor piece it still lacks
    - one TNT and one stone pressure plate for `tnt_trap` styles
    - the raw ore and ingots its next tier of tools is made of (up to what the tools of that tier it still lacks
      take, ingots before raw ore)
    - the End trip's kit and its share of the eyes of ender while its style goes to the End
    - one elytra and its firework rockets
    - one empty shulker box
    - while it's building something, that building's blocks, glass, doors, chests, beds, crafting tables and
      furnaces

    Everything else goes to the base. It picks the chest that already holds the item first, then the nearest one
    with room. The dragon egg and the dragon head go alone into the innermost chest, and holding the egg makes
    stowing as urgent as it ever gets.
  </AccordionItem>
  <AccordionItem title="Hidden bases under the hood">
    The room needs three layers of cover (its roof and two more). Every cell of room and tunnel has to be natural
    ground that doesn't fall (stone, dirt, ores; no sand or gravel), all diggable within 3,000 ticks with the bot's
    tools. The seal is the mouth's two cells, feet and head, laid with any placeable block. The pathfinder has an
    `unseal` move that breaks it and a trailing step that lays it again behind the bot. Protection covers the rooms
    and the tunnel (the base's bounds plus the usual margin), and the night's safe ground is the base's yard, which
    holds the rooms. Limits: the portal stands in the open, the mine starts outside the mouth, and a bot that
    shuts a door and seals the mouth in the same tick keeps only the later of the two.
  </AccordionItem>
  <AccordionItem title="Commands to inspect a base">
    ```txt title="Commands"
    /aiplayer info Ann            the base:, corner: and camp: lines, and the house size on the memory: line
    /aiplayer info Ann chests     every chest of the base and Nether camp, one line each, read live where loaded
    ```

    Operators can also make a bot build on demand with `/aiplayer debug Ann task build house`,
    `task build storehouse` or `task build portal` (see
    [Inspecting and debugging bots](/ai-players/reference/debugging/)).
  </AccordionItem>
  <AccordionItem title="Known limits">
    - Houses have a single floor and a flat roof, with no pitched roofs, slabs, stairs or panes yet.
    - Chests aren't sorted beyond putting an item where it already is.
    - Where no sheep live, the bed waits for twelve string. A hidden base has no farm, pen or corner.
    - The machine yard has four spots. A faction with more machines places the rest where the bot stands.
    - Each faction has one main base in the Overworld, plus at most one [camp](/ai-players/guide/nether/#the-nether-camp)
      beside its arrival portal in each other dimension.
  </AccordionItem>
</Accordions>
