Custom blocks
This section of the docs assumes you understand the basics of Rebar items.
Adding a custom block requires 3 things:
- A block class
- A
NamespacedKeythat identifies your block - A corresponding
PylonItem(Not strictly needed, but recommended so players can place your block)
Block classes
In Rebar, each type of block has its own class. Instances of that class represent blocks in the world. For example, there is an instance of the WaterPump class for every single loaded water pump in the world.
Each block class needs two constructors: the 'place' constructor (called when the block is placed) and the 'load' constructor (called when the block is loaded).
Below is a very simple example of a block class which doesn't do anything interesting.
Registering blocks
Registering a block is straightforward. First, we need to create a key:
| ExampleAddonKeys.java | |
|---|---|
Next, we can register the block:
Blocks should be registered from your addon's onEnable method.
We recommend creating a separate file which handles registering all your blocks, to avoid your onEnable function becoming huge.
Registering a block does not register a corresponding item for the block. We will need to register a corresponding item so that players can get the block as an item. Usually, the same key is used for the item and the block. As our item does not need any special behaviour, we will just use the RebarItem class for the item:
| ExampleAddonItems.java | |
|---|---|
We also need language file entries for the item:
This is all that is required to add a simple custom block.
