EntityRegistry
Package: com.hypixel.hytale.server.core.modules.entity
public class EntityRegistry extends Registry<EntityRegistration>A plugin-scoped registry for registering custom entity types. Obtained via PluginBase.getEntityRegistry(). All entity registrations made through this registry are automatically cleaned up when the owning plugin shuts down.
Extends Registry<EntityRegistration>, which provides lifecycle management, precondition checking (the plugin must not be in NONE or DISABLED state), and automatic unregistration on shutdown.
Constructor
Section titled “Constructor”public EntityRegistry(@Nonnull List<BooleanConsumer> registrations, BooleanSupplier precondition, String preconditionMessage)Constructs the registry with the given registration list, precondition supplier, and error message. The EntityRegistration::new copy constructor is passed to the parent Registry for creating plugin-scoped registration copies. Called by the plugin framework — plugins do not construct this directly.
Methods
Section titled “Methods”@Nullablepublic <T extends Entity> EntityRegistration registerEntity( @Nonnull String key, @Nonnull Class<T> clazz, Function<World, T> constructor, DirectDecodeCodec<T> codec)Registers a new entity type with the server.
Parameters:
key— the string identifier for the entity type (e.g.,"MyCustomEntity")clazz— the entity classconstructor— a factory function that creates new instances given aWorldcodec— the deserialization codec for loading entities from storage, ornullif the entity type does not persist
Returns: An EntityRegistration handle, or null if the underlying EntityModule is disabled.
Throws: IllegalStateException if the plugin precondition is not met.
Internally delegates to EntityModule.get().registerEntity(), which creates the ECS component type and registers legacy holder/ref systems.
Example
Section titled “Example”@Overrideprotected void setup() { EntityRegistration reg = getEntityRegistry().registerEntity( "MyNPC", MyNPC.class, world -> new MyNPC(world), MyNPC.CODEC );}Related Types
Section titled “Related Types”- EntityRegistration — the handle returned by registration
- EntityModule — performs the actual entity registration
Registry— base class providing lifecycle managementEntity— base entity typePluginBase— providesgetEntityRegistry()to obtain this registry