BuilderFactory
Package: com.hypixel.hytale.server.npc.asset.builder
public class BuilderFactory<T> implements SchemaConvertable<Void>, NamedSchemaFactory for creating Builder instances from JSON type discriminators. Each factory manages a map of named builder suppliers for a single category (e.g., Role, Action, Sensor). When reading JSON, the factory looks up the type tag value (default key: "Type") and instantiates the corresponding builder. Every factory automatically registers a "Component" builder that creates a BuilderComponent.
Type Parameters
Section titled “Type Parameters”| Parameter | Description |
|---|---|
T | The runtime type produced by builders in this factory. |
Constants
Section titled “Constants”| Constant | Type | Value |
|---|---|---|
DEFAULT_TYPE | String | "Type" |
COMPONENT_TYPE | String | "Component" |
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
typeTag | String | The JSON key used as the type discriminator. |
defaultBuilder | Supplier<Builder<T>> | Optional default builder for when no type tag is present. |
category | Class<T> | The category class. |
buildersSuppliers | Map<String, Supplier<Builder<T>>> | Registered builder suppliers by name. |
Constructors
Section titled “Constructors”public BuilderFactory(Class<T> category, String typeTag)public BuilderFactory(Class<T> category, String typeTag, Supplier<Builder<T>> defaultBuilder)Methods
Section titled “Methods”@Nonnullpublic BuilderFactory<T> add(String name, Supplier<Builder<T>> builder)Registers a named builder supplier. Throws if the name is already registered or the type tag is empty.
getCategory
Section titled “getCategory”public Class<T> getCategory()createBuilder
Section titled “createBuilder”public Builder<T> createBuilder(@Nonnull JsonElement config)Creates a builder from a JSON element by reading the type tag. Falls back to the default builder for non-object elements.
@Nonnullpublic Builder<T> createBuilder(String name)Creates a builder by name. Validates the category matches.
tryCreateDefaultBuilder
Section titled “tryCreateDefaultBuilder”@Nullablepublic Builder<T> tryCreateDefaultBuilder()Returns a new default builder instance, or null if none is configured.
getKeyName
Section titled “getKeyName”public String getKeyName(@Nonnull JsonElement config)Extracts the type tag value from a JSON element without creating a builder.
getBuilderNames
Section titled “getBuilderNames”@Nonnullpublic List<String> getBuilderNames()Returns all registered builder names.
getSchemaName
Section titled “getSchemaName”@Nonnull@Overridepublic String getSchemaName()Returns "NPCType:" + category.getSimpleName().
toSchema
Section titled “toSchema”@Nonnull@Overridepublic Schema toSchema(@Nonnull SchemaContext context)Generates a conditional JSON Schema where the if/then/else structure selects the correct builder schema based on the type tag value.
Related Types
Section titled “Related Types”- Builder — the interface of created objects
- BuilderComponent — default
"Component"builder - BuilderManager — registers and retrieves factories