Block IDs
blockIdProvider() generates a context int provider that turns the block read by compute block into a number, so one command stores "which block is this" in a score instead of one execute if block per candidate.
- Objectives: none, the score you store the result in is yours.
- Storage: none.
- Entities: none.
- Forceloaded chunks: none.
- Every tick: no.
- Load and files: the context int provider
kore_block_idand one block tag per bit (kore_block_id/bit_0,kore_block_id/bit_1...), generated once per pack however many timesblockIdProvider()is called.
API overview
| Function | Result |
|---|---|
DataPack.blockIdProvider() |
The ContextIntProviderArgument of <pack>:kore_block_id, created on the first call. |
blockId(block) |
The ID of a block as an Int known at build time, to compare the score against. |
blockIdBits |
The number of bits of an ID, which is the number of generated tags. |
An ID is the 1-based position of the block in Kore's generated Blocks enum, so blockId(Blocks.ACACIA_BUTTON) is 1. A block Kore doesn't know, a modded one for instance, has the ID 0, and block states are ignored: a stair facing any side, upside down or not, has the ID of Blocks.OAK_STAIRS.
IDs follow the block list of the Minecraft version Kore targets, so they change between versions. Compare against blockId(...) instead of writing numbers by hand, and never store an ID across a version update.
How it works
The provider sums one match_block check per bit of the ID. Each check tests the block against a generated block tag listing every block whose ID has that bit set, and adds 2^bit when it passes:
With the roughly 1300 blocks of the current versions, an ID takes 11 bits (blockIdBits), so each evaluation runs 11 match_block checks: use it where one compute per tick or per event is enough, and keep a plain execute if block for a single known block.
Limits
match_blockonly reads the block of acompute block <pos>command. Incompute defaultorcompute entity, no check passes and the result is0.- A block that breaks or changes as soon as it is placed (a rail without support, a plant without ground) can't be read as the block you placed: the provider reads the block that is really there.
See also
- Commands - The
computecommand and the other context providers. - Loot Tables - Context provider files.
- Tags - The block tags the provider is built from.
