Skip to content

Refactor how blocks and items are defined#228

Merged
StackDoubleFlow merged 7 commits intomasterfrom
dev/stack/blocks-refactor
Mar 6, 2026
Merged

Refactor how blocks and items are defined#228
StackDoubleFlow merged 7 commits intomasterfrom
dev/stack/blocks-refactor

Conversation

@StackDoubleFlow
Copy link
Member

This PR aims to solve two issues:

  1. It aims to lower the barrier of entry to adding blocks and items to MCHPRS for new contributors.
  2. It aims to make it significantly easier to update MCHPRS to a new game version.

Previously, adding a new block, even an extremely simple one, was a combersome process, which essentially boiled down to:

  1. Obtain the JSON file containg block ids using the data generator.
  2. Create an entry in the blocks! macro invocation, manually mapping the block id and name to the new enum variant. If the block has properties, then you may have to do a little math to encode/decode them.
  3. Create an entry in the items! macro invocation, again manually mapping the id. Most items didn't even have a name mapping.
  4. Create a mapping from item to block for placement in the core::interaction module.

Then, when updating to a new game version, one would have to manually go through these massive macros and update the ids. Additionally, there are hardcoded protocol ids dotted around MCHPRS which can be hard to spot during an update. As a comical example, when we updated to 1.20.4, we missed the player entity id, so other players appeared as zombie villigers. There are other other types of protocol ids including note block sound ids, command argument type ids, and inventory type ids.

This PR solves these problems by introducing a single yaml file that contains a list of of the name of all blocks and items implemented by MCHPRS. It also checks in the generated blocks.json and registries.json. These 3 files are used in the new block_data_gen which generates a single rust file containing the Block and Item enum, and many other generated implementations. To solve the problem where protocol ids are hardcoded everywhere, this PR introduces the new procedural macro protocol_id! which can look up protocol id from registries.json. For example, to look up the entity id for a player, it's as simple as protocol_id!("minecraft:entity_type", "minecraft:player").

@StackDoubleFlow StackDoubleFlow force-pushed the dev/stack/blocks-refactor branch from f44a6f4 to 522e527 Compare March 6, 2026 10:03
@StackDoubleFlow StackDoubleFlow merged commit d7e389b into master Mar 6, 2026
9 checks passed
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