Skip to content

refactor(world/chunk): make block registry instance-scoped#1171

Open
HashimTheArab wants to merge 22 commits intodf-mc:masterfrom
HashimTheArab:feat/block-registries
Open

refactor(world/chunk): make block registry instance-scoped#1171
HashimTheArab wants to merge 22 commits intodf-mc:masterfrom
HashimTheArab:feat/block-registries

Conversation

@HashimTheArab
Copy link
Contributor

@HashimTheArab HashimTheArab commented Jan 14, 2026

Credit to @olebeck, most of the code was taken from his fork.

  • Replace global block palette/light lookups with an instance-scoped BlockRegistry passed through chunks/encoding.
  • Remove global LightBlocks/FilteringBlocks and derive per-runtimeID flags (light, filter, NBT, random tick, liquids) from the active registry.
  • Eliminate incremental slices.Insert(...) maintenance of parallel runtimeID-indexed slices; derived lookup tables are built in Finalize().
  • Enables running multiple servers in one process and safely supports per-server custom block registries without global conflicts.

Closes #1170

… palette/light caches)

- Replace global block palette/light lookups with an instance-scoped BlockRegistry passed through chunks/encoding.
- Remove global LightBlocks/FilteringBlocks and derive per-runtimeID flags (light, filter, NBT, random tick, liquids) from the active registry.
- Eliminate incremental slices.Insert(...) maintenance of parallel runtimeID-indexed slices; derived lookup tables are built in Finalize().
- Fix LightArea baseZ bug and make lighting queries registry-aware.
- Make Flat generator resolve runtime IDs against the chunk’s registry (supports custom registries).
- Enables running multiple servers/worlds in one process and safely supports per-server custom block registries without global conflicts.
- mcdb: make ColumnIterator.Column() lazily load columns; Next() only advances keys and clears the cached column to avoid stale returns.
registerBlockState(s)
}

chunk.RuntimeIDToState = func(runtimeID uint32) (name string, properties map[string]any, found bool) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were moved to BlockRegistryImpl

stateRuntimeIDs = map[stateHash]uint32{}
// nbtBlocks holds a list of NBTer implementations for blocks registered that implement the NBTer interface.
// These are indexed by their runtime IDs. Blocks that do not implement NBTer have a false value in this slice.
nbtBlocks []bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the below ones were moved to blockState in BlockRegistryImpl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

block registry is using global variables

1 participant