Adding a New Block (Basic Setup)
⚠️ This is only the very basic setup and does not provide any functionality yet.
1. Select Which Block to Add
Section titled “1. Select Which Block to Add”At first, select which block you want to add to the project.
Example: In this guide, we want to add Iron Bars and Copper Bars.
2. Check the Class Name in classes.json
Section titled “2. Check the Class Name in classes.json”Before we can create our struct, we need to check how to name it properly.
Go to the file:
steel-core/build/classes.jsonSearch for your block in this file. In our example:
- We find
IronBarsBlock - We find
WeatheringCopperBarsBlock
This means we need two different structs to manage both blocks.
3. Create Your Block Class File
Section titled “3. Create Your Block Class File”Now create your class in:
steel-core/src/behavior/blocks/Be as descriptive as possible with the file name. For our example:
iron_bars_block.rscopper_bars_block.rs
4. Add the Struct Definition
Section titled “4. Add the Struct Definition”Add the struct like this to your file:
pub struct IronBarsBlock { block: BlockRef,}
impl IronBarsBlock { /// Creates a new bar block behavior for the given block. #[must_use] pub const fn new(block: BlockRef) -> Self { Self { block } }}
impl BlockBehaviour for IronBarsBlock {}⚠️ This is only the basic setup and doesn’t give any functionality yet!
5. Register the Block Module
Section titled “5. Register the Block Module”To register the block, there needs to be the attribute block_behavior added!
#[block_behavior]pub struct IronBarsBlock { block: BlockRef,}
impl IronBarsBlock { /// Creates a new bar block behavior for the given block. #[must_use] pub const fn new(block: BlockRef) -> Self { Self { block } }}
impl BlockBehaviour for IronBarsBlock {}⚠️ More complex blocks than the iron bar block have properties, you can find more information here more information!
6. Compile the Project
Section titled “6. Compile the Project”Now press compile and let Rust (and our configuration) do some magic!
After compilation, your block should appear in:
steel-core/src/behavior/generated/blocks.rsYou can go there and use Ctrl + F to search for your block name.
Troubleshooting
Section titled “Troubleshooting”If your block is still missing:
-
Delete the
generatedfolder -
Run:
cargo clean -
Compile again
This should solve the problem.
Adding Behavior to the Block
Section titled “Adding Behavior to the Block”Like already said, at this point the block does nothing.
To add behavior, you need to implement the necessary methods in BlockBehaviour in your file (e.g. iron_bars_block.rs).
👉 I would recommend looking at other block implementations to check which have similar block functionality as your block.
For that, here is some information to give you a better understanding:
Working with Block States
Section titled “Working with Block States”Getting a Block State
Section titled “Getting a Block State”To get a block state, you can do something like this:
let west_pos = Direction::West.relative(pos);let west_state = world.get_block_state(&west_pos);In this block state, all information of this specific block is saved.
Modifying Block State Properties
Section titled “Modifying Block State Properties”This can be changed like this:
state.set_value(&BlockStateProperties::WEST, true);Getting a value is vice versa.
Checking Neighbor Blocks or Tags
Section titled “Checking Neighbor Blocks or Tags”To check if the neighbor or the block set is a specific block or block group (like bars or walls), you can use this:
let walls_tag = Identifier::vanilla_static("walls");if REGISTRY.blocks.is_in_tag(neighbor_block, &walls_tag) { return true;}That’s it — you now have the basic structure in place and can start implementing real behavior 🚀
Other useful resources
Section titled “Other useful resources”- using properties for blocks and items, you can find information here