Skip to content

BuilderFactory

Package: com.hypixel.hytale.server.npc.asset.builder

public class BuilderFactory<T> implements SchemaConvertable<Void>, NamedSchema

Factory 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.

ParameterDescription
TThe runtime type produced by builders in this factory.
ConstantTypeValue
DEFAULT_TYPEString"Type"
COMPONENT_TYPEString"Component"
FieldTypeDescription
typeTagStringThe JSON key used as the type discriminator.
defaultBuilderSupplier<Builder<T>>Optional default builder for when no type tag is present.
categoryClass<T>The category class.
buildersSuppliersMap<String, Supplier<Builder<T>>>Registered builder suppliers by name.
public BuilderFactory(Class<T> category, String typeTag)
public BuilderFactory(Class<T> category, String typeTag, Supplier<Builder<T>> defaultBuilder)
@Nonnull
public 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.

public Class<T> getCategory()
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.

@Nonnull
public Builder<T> createBuilder(String name)

Creates a builder by name. Validates the category matches.

@Nullable
public Builder<T> tryCreateDefaultBuilder()

Returns a new default builder instance, or null if none is configured.

public String getKeyName(@Nonnull JsonElement config)

Extracts the type tag value from a JSON element without creating a builder.

@Nonnull
public List<String> getBuilderNames()

Returns all registered builder names.

@Nonnull
@Override
public String getSchemaName()

Returns "NPCType:" + category.getSimpleName().

@Nonnull
@Override
public 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.

Hydex is an independent community resource. Hytale is a trademark of Hypixel Studios. Hydex is not affiliated with or endorsed by Hypixel Studios.