Skip to content

BuilderBase

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

public abstract class BuilderBase<T> implements Builder<T>

The abstract base implementation of the Builder interface. Provides the complete infrastructure for reading NPC JSON configuration files: attribute parsing (strings, ints, doubles, booleans, enums, arrays, assets, objects), expression evaluation, validation, schema generation, feature evaluation, state mapping, and instruction context handling.

This is the largest class in the builder package. Concrete builder types (for Actions, Sensors, BodyMotions, HeadMotions, Instructions, etc.) extend BuilderBase and override readConfig(JsonElement) to declare their specific JSON attributes.

ParameterDescription
TThe runtime type this builder produces.
FieldTypeDescription
fileNameStringName of the JSON file being read.
queriedKeysSet<String>Set of JSON keys that have been read, used to detect unknown attributes.
useDefaultsOnlybooleanWhen true, attribute readers return defaults without reading JSON.
labelStringLabel for breadcrumb error reporting.
typeNameStringType discriminator name from the factory.
evaluatorHelperFeatureEvaluatorHelperFeature provider evaluation.
stateHelperStateMappingHelperState machine index mapping.
instructionContextHelperInstructionContextHelperInstruction context validation.
builderParametersBuilderParametersParameter definitions and scope.
builderManagerBuilderManagerThe manager loading this builder.
builderDescriptorBuilderDescriptorSchema descriptor.
readErrorsList<String>Errors accumulated during read.
public final void readConfig(BuilderContext owner, @Nonnull JsonElement data, BuilderManager builderManager, BuilderParameters builderParameters, BuilderValidationHelper builderValidationHelper)

Orchestrates the full read lifecycle:

  1. preReadConfig — initializes fields from the validation helper.
  2. readCommonConfig — reads common attributes shared by all builders.
  3. readConfig(JsonElement) — subclass-specific attribute reading (abstract).
  4. postReadConfig — detects unknown JSON keys.
@Nonnull
public abstract Builder<T> readConfig(@Nonnull JsonElement data);

Subclasses override this to read their specific JSON attributes.

@Nullable
public abstract String getShortDescription();

Returns a brief description for schema/documentation.

@Nullable
public abstract String getLongDescription();

Returns a detailed description for schema/documentation.

BuilderBase provides a large family of require* and optional* methods for reading typed values from JSON. Each method registers the key, reads the value, validates it, and feeds it to a consumer or holder. Key families include:

  • Strings: requireString, optionalString, requireStringList, readString
  • Numbers: requireInt, optionalInt, requireDouble, optionalDouble, requireFloat, optionalFloat
  • Booleans: requireBoolean, optionalBoolean
  • Enums: requireEnum, optionalEnum, requireEnumSet, optionalEnumArray
  • Arrays: requireNumberArray, optionalNumberArray, requireStringArray, optionalStringArray, requireBooleanArray, optionalTemporalArray
  • Assets: requireAsset, optionalAsset, requireAssetArray
  • Objects: requireObject, optionalObject, requireObjectList, requireObjectMap
  • Codec objects: requireCodecObject, optionalCodecObject
public static JsonElement expectKey(@Nonnull JsonObject jsonObject, @Nonnull String key)

Returns the value for a required JSON key, throwing if absent.

public static JsonObject expectObject(@Nonnull JsonElement element)
public static JsonObject expectObject(@Nonnull JsonElement element, @Nonnull String name)

Casts a JSON element to an object, throwing a descriptive error on type mismatch.

public static boolean readBoolean(@Nonnull JsonObject data, @Nonnull String key, boolean defaultValue)
public static String readString(@Nonnull JsonObject data, @Nonnull String key)
public static String readString(@Nonnull JsonObject data, @Nonnull String key, String defaultValue)
public static String[] readStringArray(@Nonnull JsonObject data, @Nonnull String key, StringValidator validator, BuilderParameters parameters)

Static helpers for reading primitives and arrays from JSON objects.

public static <E extends Enum<E>> String getDomain(E[] constants)

Generates a comma-separated domain string from enum constants.

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