Skip to main content

Environment API

The environment API is for attachment-backed state and datapack-backed worldgen. It is separate from crop registration; crops, machines, and blocks can consume these handles from their own logic.

Entry Points

What you wantEntry pointReturns
Raw NeoForge attachmentattachmentType("id", holder -> defaultValue)AttachmentTypeBuilder<T, RegistryCore>
Chunk-scoped statechunkState("id", codec, defaultValue)ChunkStateBuilder<T, RegistryCore>
World-scoped stateworldState("id", codec, defaultValue)WorldStateBuilder<T, RegistryCore>
Configured and placed worldgenworldgenFeature("id", configuredFeature)WorldgenFeatureBuilder<C, RegistryCore>

AttachmentTypeBuilder

MethodParametersDescription
configure(callback)UnaryOperator<AttachmentType.Builder<T>>Apply low-level NeoForge attachment configuration
serialize(codec)MapCodec<T>Configure persistent attachment serialization
sync(streamCodec)StreamCodec<? super RegistryFriendlyByteBuf, T>Configure attachment sync
register()-Register and return AttachmentTypeEntry<T>

AttachmentTypeEntry

MethodReturn typeDescription
get()AttachmentType<T>Get the registered NeoForge attachment type
getOrCreate(holder)TRead or create data on an IAttachmentHolder
getIfPresent(holder)Optional<T>Read existing data without creating it
set(holder, value)TReplace attachment data and return the previous value
remove(holder)TRemove attachment data and return the previous value
sync(holder)voidSync attachment data through NeoForge

ChunkStateBuilder

MethodParametersDescription
syncOnModify(enabled)booleanRequest sync after set or modify when a sync codec exists
sync(streamCodec)StreamCodec<? super RegistryFriendlyByteBuf, T>Configure sync and enable sync-on-modify
debug()-Enable read-only debug commands with default permissions
debug(configurator)UnaryOperator<StateDebugConfig>Enable and configure debug command permissions and writability
register()-Register and return ChunkStateEntry<T>
build()-Register and return the parent chain object

ChunkStateEntry

MethodReturn typeDescription
identifier()IdentifierLogical state id
scope()StateScopeAlways CHUNK
codec()Codec<T>Persistent value codec
attachmentType()AttachmentType<T>Underlying attachment type
debugConfig()StateDebugConfigDebug command configuration
getOrCreate(level, chunkPos)TRead or create chunk state
getIfLoaded(level, chunkPos)Optional<T>Read without force-loading the chunk
set(level, chunkPos, value)voidReplace the value and mark the chunk unsaved
modify(level, chunkPos, action)voidMutate the value and mark the chunk unsaved
sync(level, chunkPos)voidManually sync the state

WorldStateBuilder

MethodParametersDescription
syncOnModify(enabled)booleanRequest sync after set or modify when a sync codec exists
sync(streamCodec)StreamCodec<? super RegistryFriendlyByteBuf, T>Configure sync and enable sync-on-modify
debug()-Enable read-only debug commands with default permissions
debug(configurator)UnaryOperator<StateDebugConfig>Enable and configure debug command permissions and writability
register()-Register and return WorldStateEntry<T>
build()-Register and return the parent chain object

WorldStateEntry

MethodReturn typeDescription
identifier()IdentifierLogical state id
scope()StateScopeAlways WORLD
codec()Codec<T>Persistent value codec
attachmentType()AttachmentType<T>Underlying attachment type
debugConfig()StateDebugConfigDebug command configuration
getOrCreate(level)TRead or create world state
getIfPresent(level)Optional<T>Read without creating state
set(level, value)voidReplace the value
modify(level, action)voidMutate the value
sync(level)voidManually sync the state

StateDebugConfig

MethodDescription
enabled(boolean)Enable or disable debug command visibility
writable(boolean)Allow set commands
readPermission(int)Permission level for list, get, and debug
writePermission(int)Permission level for set

WorldgenFeatureBuilder

MethodParametersDescription
placement(modifier)PlacementModifierAdd one placed feature modifier
placements(modifiers)List<PlacementModifier>Add multiple placed feature modifiers
addToBiomes(tag, step)TagKey<Biome>, GenerationStep.DecorationGenerate an AddFeaturesBiomeModifier for matching biomes
register()-Generate configured/placed feature data and return WorldgenFeatureEntry
build()-Register and return the parent chain object

WorldgenFeatureEntry

MethodReturn typeDescription
configuredKey()ResourceKey<ConfiguredFeature<?, ?>>Key for the generated configured feature
placedKey()ResourceKey<PlacedFeature>Key for the generated placed feature

See Also