Skip to content
Tslat edited this page Sep 2, 2022 · 5 revisions

SmartBrainLib is a library designed to expand and optimise the Brain system in Minecraft.

Contents

Why?

The Brain system in Minecraft is an incredibly useful and powerful AI system for Minecraft entities. It's functionally superior to the goal system in just about every way, and allows mod authors to combine much more complex entity behaviours without needing to store a slew of additional variables in the entity's class, and re-writing goals repeatedly to support niche uses.

The problem however, is that Minecraft's implementation of the Brain system is very poor, very restrictive, and very lacking. It has a lot of potential, but doesn't make use of much of it at all, and instead goes for the most straightforward setup in a way that lacks foresight.

Let's look at some of the issues.

Efficiency

The brain system was designed incredibly inefficiently, requiring creation and re-creation of numerous unnecessary objects on a regular basis, over-using streams for very simple functions, and serializing/deserializing memories for entities that will likely never need to have their memories saved. This creates a massive overhead for both entity instantation, and entity runtime. While this may not make too much difference on an individual basis; Minecraft's inherent nature benefits massively from performance improvements, and a lot can be gained here.

Over-Abstraction

Minecraft likes to abstract objects away that it often has no reason to. This is evident in a few places in the Brain system, such as Sensor-factories, MemoryModuleType management, and Behaviour management. This is problematic for modders because it means we have much less flexibility and access to control over the entities we want to customise - often to the point where it's easier to just deal with the goal system instead.

Extensibility

Mojang made a smart move in changing the way they handle individual behaviours, as opposed to Goals - in that behaviours operate on a 'per-function' basis. I explain this in more detail on the Brain page, but in short this means that they designed a system intended for extensibility and flexibility, but then locked it all down and used none of it. This is especially problematic when compared to Goals, which are inherently reasonably extensible. Having to make a whole new behaviour for every new little thing you want to do is very problematic, and just leads to massive bloat, and defeats the purpose of the brain system to begin with.

Usability

The way the brain system was designed means that to use the system by default you really need to pore over the existing examples of brain AI (Piglin, villager, etc) and study exactly how everything is laid out and used, and even then you're still left confused as to how things should be laid out. Additionally when you do finally work it out, it's not at all clear or intuitive how to add more to it, leaving users just completely lost in attempts to try and utilise the system in its entirety. Compare that to goals where you simply create a new instance of a goal and add it to the selector, and you immediately notice a major usability problem. The fact that you essentially need an entirely new class just to handle the AI for your mob begins to show just how poorly this was thought out, and how inefficient it is at scale.

The Solution

To resolve all these issues; SmartBrainLib (SBL) completely replaces the vanilla brain system, using a custom brain, brain provider, memories, sensors, and behaviours. It attempts to maintain compatibility with the existing system where possible, however due to the limitations of the existing implementation, it's not feasible to maintain full compatibility with vanilla's existing systems. This shouldn't matter however, as most interactions other mods would typically have with brains should be natively compatible with SBL's replacements.

SBL is built on two main goals:

  1. Make it fast
  2. Make it usable

With these two in mind, SBL has managed a significant performance increase over the vanilla brain system - to the point where conservative implementation of sensors and behaviours could make your entity run more efficiently than an equivalent entity on the goals system. This, whilst simultaneously greatly increasing the usability, flexibility, and simplicity of the system as a whole. You no longer need entire new classes to handle your mob's AI - do it all in the entity class itself!

When would I use SBL?

As much as SBL improves the brain system, it is still the brain system it runs on. This means that for those more familiar with goals, happy to use existing basic goal implementations, or for those who just want something super quick and easy, the goal system is still likely for you.

The brain system is for more complex or nuanced AI, or for those who find a particular interest/preference in the way the brain system works. It's worth noting that the individually-encapsulated way behaviours are designed, the code footprint of an entity's AI using SBL will still be larger than one using goals, but the advantage lies in that SBL's system is much easier to understand and expand.

If you want to learn more about SBL, want help using it, or just want to discuss it, jump into the Discord

Clone this wiki locally