Skip to content

Blocks API#66

Open
SpaceWalkerRS wants to merge 2 commits into
gen2from
blocks
Open

Blocks API#66
SpaceWalkerRS wants to merge 2 commits into
gen2from
blocks

Conversation

@SpaceWalkerRS
Copy link
Copy Markdown
Member

The main purpose of this API is to provide a hook for registering blocks. As a bonus it also injects one or two utility methods into the Block class.

Features

Block Registration

The REGISTER_BLOCKS event is invoked right after Vanilla block registration has completed. Custom block registration should be done in a listener to this event.

The BlockRegistry class provides static access to the block registry:

int getId(Block)
NamespacedIdentifier getKey(Block)

Block getBlock(int)
Block getBlock(NamespacedIdentifier)

Set<NamespacedIdentifier> keySet()

// 17w46a-
Block register(int, NamespacedIdentifier, Block)
// 17w47a+
Block register(NamespacedIdentifier, Block)

1.6 And Below

In Minecraft 1.6.4 and below, there was no block registry. Instead, blocks were stored in a single array. This API provides its own registry for these versions, and even registers all Vanilla blocks using the relevant namespaced IDs from 1.7.

Air Block

Air did not have a block associated with it until 13w38b. OSL provides an air block in versions before that.

Injected methods

Two methods are added to Block using transitive inteface injection:

  • boolean isAir() in 17w46a and below
  • `boolean is(Block) in 1.6.4 and below

@SpaceWalkerRS SpaceWalkerRS force-pushed the blocks branch 2 times, most recently from 4994699 to 20d9abd Compare May 30, 2026 15:18
@SpaceWalkerRS SpaceWalkerRS force-pushed the gen2 branch 3 times, most recently from 214d13e to 8f7ec06 Compare May 31, 2026 08:36
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.

1 participant