Skip to content

Instantly share code, notes, and snippets.

@Pyrofab
Created December 12, 2019 11:39
Show Gist options
  • Save Pyrofab/296b86ba1c6ec2df7fbf077919414ca2 to your computer and use it in GitHub Desktop.
Save Pyrofab/296b86ba1c6ec2df7fbf077919414ca2 to your computer and use it in GitHub Desktop.

Brains, Schedules and Activities: An overview of the new 1.14 AI system

In 1.14, villagers use an AI system completely independent from the old Goal system. However, this system can be used by any LivingEntity. This document aims at explaining the basics of that more advanced AI.

Every living entity now has a Brain. A brain uses memories and sensors to perform tasks and activities.

Memories

Memories are a way to save arbitrary data for use by tasks.

To be persistent, a MemoryModuleType must have a factory for deserialization, and its value must implement DynamicSerializable.

Senses

Senses are updated every 10 ticks and provide short term memories to the brain.

Tasks

Tasks work much like their counterpart Goal, but much more generic. A task can have two states, STOPPED and RUNNING. When a brain starts a task, it first checks that the owning entity has the required memory state, then performs task-specific checks. If those checks pass, the task transitions to the RUNNING state.

Tasks are one-shots by default, their run method is executed once, then next tick they get stopped. If the task overrides shouldKeepRunning, its execution can span multiple ticks.

Tasks have no integrated concept of mutual exclusion.

Activities

Activities are identifier classes used to describe a list of tasks. They do not have any actual logic; brains execute tasks from their task lists based on the current activity. Each activity must have a task calling Brain#doActivity to refresh the activity performed by the brain.

Technical corner

Each brain has a priority => activity => tasks map, meaning tasks with the same priority get grouped by activity. Each tick, the brain selects all tasks from the current activity that are currently stopped, and tries starting them in order, lowest priority first.

Schedules

A schedule is a collection of activities beginning at specific times. An activity's starting time is specified in game ticks, and will begin every day at that time (a day has 24000 ticks, starting at sunrise). There are 4 default schedules:

  • EMPTY - the default schedule for every entity in the game. Has a single "empty" activity, which does not do anything.
  • SIMPLE - an unused simple schedule. Has a "work" activity beginning at 5000 ticks (in the morning) and a "rest" activity beginning at 11000 ticks (in the evening).
  • VILLAGER_BABY - the schedule for baby villagers, with "idle", "play", "idle", "play" and "rest" activities.
  • VILLAGER_DEFAULT - the schedule used by adult villagers, with "idle", "work", "meet", "idle" and "rest" activities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment