Skip to Content
DocsAPIOverview

Overview

Better Ecology provides APIs for:

  • Accessing entity ecology data
  • Registering custom behavior handles
  • Modifying entity configurations
  • Querying spatial data

Core Interfaces

EcologyAccess

Access ecology components from entities:

EcologyComponent component = ((EcologyAccess) entity).getComponent();

EcologyHandle

Interface for implementing custom behavior systems:

public interface EcologyHandle { boolean supports(EcologyProfile profile); void registerGoals(Mob mob, GoalSelector goals, GoalSelector targets); void tick(Mob mob); void readNbt(CompoundTag tag); void writeNbt(CompoundTag tag); }

EcologyComponent

Per-entity data storage:

// Read handle data CompoundTag hungerTag = component.getHandleTag("hunger"); float hunger = hungerTag.getFloat("current"); // Write handle data CompoundTag tag = component.getOrCreateHandleTag("hunger"); tag.putFloat("current", newValue);

Registering Custom Handles

Register handles during mod initialization:

EcologyHandleRegistry.register("my_handle", new MyCustomHandle());

Custom handles are automatically enabled for entities whose profiles include the handle’s configuration keys.

Spatial Queries

Query nearby entities efficiently:

List<Entity> neighbors = SpatialIndex.getNeighbors( entity.position(), radius, entity.getType() );

Events

Better Ecology fires events at key lifecycle points:

  • Profile reload
  • Goal registration
  • Entity tick
  • NBT save/load

Further Documentation

Last updated on