Block interfaces
Rebar has a number of builtin interfaces which add custom behaviour to blocks. For example, there are interfaces which allow you to:
- add fluid buffers (RebarFluidBufferBlock)
- run code when the block is clicked (RebarInteractBlock)
- run code when a player jumps on top of a block (RebarJumpBlock)
- ...and many many more
How do I use interface X?
- Check if it has any documentation on this site (scroll down).
- Read the JavaDocs of the interface and of the relevant methods.
- Check for examples in Pylon or other addons where the interface is used.
- Ask for help on the Pylon Discord.
For example, suppose you want to spawn particles when the block is right clicked.. You can do this using RebarInteractBlock:
The postLoad method
Many block interfaces store persistent data. Instead of forcing you to load and save the data yourself in the write method and your load constructor, all of Rebar's block interfaces have a separate mechanism for saving their data to the block's PDC. A side effect of this is that the block's load constructor is called, none of Rebar's block interfaces will have loaded their data yet. Therefore, as a rule of thumb, you should not call any methods related to block interfaces in your load constructor. Instead, override the postLoad method and do whatever you need to do there instead. The postLoad method will be called after all block interfaces associated with the block have loaded their data.
postInitialise
It is also worth noting the postInitialise method, which is the same as postLoad except in that it is also called after the place constructor.
Interface quick reference
-
Miscellaneous interfaces
Interfaces which do not fall into any particular category.
Interface Javadocs RebarBreakHandler Javadocs RebarDirectionalBlock Javadocs RebarFacadeBlock Javadocs RebarFallingBlock Javadocs RebarTickingBlock Javadocs RebarUnloadBlock Javadocs RebarVirtualInventoryBlock Javadocs -
Logistics interfaces
Interfaces which allow your block to interact with logistic systems, including cargo.
If you want your machine to be compatible with cargo inserters/extractors, you need to implement RebarLogisticBlock.
Interface Javadocs RebarCargoBlock Javadocs RebarLogisticBlock Javadocs -
Fluid interfaces
Interfaces which allow your block to interact with the fluid system.
You should use
RebarFluidBufferBlockandRebarFluidTankunless necessary. TheRebarFluidBlockinterface is quite abstract and designed to be as flexible as possible, requiring your machine to implement its own fluid storage logic.Interface Javadocs RebarFluidBlock Javadocs RebarFluidBufferBlock Javadocs RebarFluidTank Javadocs -
Multiblock interfaces
Interfaces which turn your block into a multiblock.
Most multiblocks you create can use RebarSimpleMultiblock. For more complex multiblocks, you can [RebarMultiblock], but this class is designed to be as flexible as possible and so is very barebones - it does not come with ghost blocks, does not account for rotation, etc.
Due to the way multiblock work under the hood, there is almost zero performance cost associated with them (contrary to what you may expect). Even extremely large multiblocks are very performance-friendly.
Interface Javadocs RebarMultiblock Javadocs RebarSimpleMultiblock Javadocs -
Vanilla interfaces
Interfaces which expose functionality of vanilla blocks. For example, if you add a block which is a beacon and want to run some code when the beacon is deactivated, you could use RebarBeacon.
Interface Javadocs RebarBeacon Javadocs RebarBell Javadocs RebarBrewingStand Javadocs RebarCampfire Javadocs RebarCauldron Javadocs RebarComposter Javadocs RebarCopperBlock Javadocs RebarCrafter Javadocs RebarDispenser Javadocs RebarEnchantingTable Javadocs RebarFlowerPot Javadocs RebarFurnace Javadocs RebarGrowable Javadocs RebarHopper Javadocs RebarJobBlock Javadocs RebarLeaf Javadocs RebarLectern Javadocs RebarNoJobBlock Javadocs RebarNoteBlock Javadocs RebarNoVanillaContainerBlock Javadocs RebarPiston Javadocs RebarRedstoneBlock Javadocs RebarShearable Javadocs RebarSign Javadocs RebarSponge Javadocs RebarTargetBlock Javadocs RebarTNT Javadocs RebarVault Javadocs RebarVanillaContainerBlock Javadocs