Skip to content

First look at strings for block type IDs#6786

Draft
dktapps wants to merge 8 commits intomajor-nextfrom
string-block-type-ids
Draft

First look at strings for block type IDs#6786
dktapps wants to merge 8 commits intomajor-nextfrom
string-block-type-ids

Conversation

@dktapps
Copy link
Member

@dktapps dktapps commented Aug 31, 2025

This solves the following issues:

  • Conflicts on BlockTypeIds every time someone makes a PR to add a new block
  • Type IDs not consistent on different threads

We still have an auto assigned type number internally, which is used to compute state IDs for runtime chunk storage. However, this is not directly exposed to plugins, and is fully dynamic.

FastChunkSerializer, instead of directly passing state IDs to the next thread, now deconstructs state IDs into their type number and state data componets, and writes a string type name + state data separately. This allows the blocks to be consistently decoded on the destination thread, particularly when custom blocks are involved, as custom blocks are expected to claim unique string type IDs

Plugins implementing custom blocks may use their Minecraft save ID as their type ID, however this is not required. A type ID must, however, be globally unique and must not conflict with any other blocks.

I haven't yet measured the performance impact to FastChunkSerializer from this change, however, I do expect some minor performance degradation, since individual calls on BinaryStream are slower than a bulk pack() / unpack() call.

Related issues & PRs

Changes

API changes

  • Block->getTypeId() now returns a string
  • All BlockTypeIds constants are now converted to string
  • BlockIdentifier now accepts string instead of int
  • Several new static methods in BlockTypeIds to facilitate internal functionality

Behavioural changes

Functionally everything should be basically the same.

Backwards compatibility

BC breaks to APIs
Block->getStateId() may now change without warning between versions. This was true previously too (since the definition of the state data could change), but the type numbers may also move around without warning now, which will affect the resulting state ID. The function is marked as @internal, but that never seems to stop anyone...

Follow-up

Consider using incrementing IDs in chunk runtime storage, and using type ID + state data as a hash key to look up state ID, rather than using type number + state data as state ID as we do currently. This would allow getting rid of type numbers completely, make chunk block ID validation easier, and remove current restrictions from state data bits (although expanding state data bits would probably require rethinking RuntimeBlockStateRegistry).

Tests

Playtested locally and PHPUnit tested.

This solves the following issues:
- Conflicts on BlockTypeIds every time someone makes a PR to add a new block
- Type IDs not consistent on different threads

We still have an auto assigned type number internally, which is used to compute
state IDs for runtime chunk storage. However, this is not directly exposed to
plugins, and is fully dynamic.
FastChunkSerializer, instead of directly passing state IDs to the next thread,
now deconstructs state IDs into their type number and state data componets,
and writes a string type name + state data separately. This allows the blocks
to be consistently decoded on the destination thread, particularly when custom
blocks are involved, as custom blocks are expected to claim unique string type
IDs

Plugins implementing custom blocks **may** use their Minecraft save ID as their
type ID, however this is not required. A type ID must, however, be globally
unique and must not conflict with any other blocks.

I haven't yet measured the performance impact to FastChunkSerializer from this
change, however, I do expect some minor performance degradation, since individual
calls on BinaryStream are slower than a bulk pack() / unpack() call.
@dktapps dktapps requested a review from a team as a code owner August 31, 2025 19:42
@dktapps dktapps added Category: API Related to the plugin API Category: Core Related to internal functionality Type: Fix Bug fix, typo fix, or any other fix BC break Breaks API compatibility Performance labels Aug 31, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Aug 31, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Aug 31, 2025
@dktapps dktapps added the Status: Incomplete Work in progress label Aug 31, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Aug 31, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Oct 22, 2025
we can do this now that the IDs are deterministic without unstable diffs.
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Oct 22, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Oct 22, 2025
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Oct 22, 2025
dktapps added a commit to pmmp/ext-chunkutils2 that referenced this pull request Oct 31, 2025
…w bytes, instead of an array" and related commits

It turns out this is only useful if we want to preserve the bytes for
direct reuse later. We don't really want to do this as discussed in
pmmp/PocketMine-MP#6786. When the data must be decomposed into integers,
transformed and repacked to binary, getting the data as binary first is
actually worse for performance (assuming that ByteBufferReader is used).
So it looks like we're stuck with arrays, for better or worse :(

This reverts commit 8e83c8d.
This reverts commit 5614724.
This reverts commit a26bed6.
@dktapps
Copy link
Member Author

dktapps commented Dec 21, 2025

This is stalled pending improvements to FastChunkSerializer and/or the structure of blockstate IDs stored in subchunks. The process of converting a state ID into a string type ID + unmasked state data feels like a hack, and will almost definitely be slow.

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

Labels

BC break Breaks API compatibility Category: API Related to the plugin API Category: Core Related to internal functionality Status: Incomplete Work in progress Type: Fix Bug fix, typo fix, or any other fix

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant