Adding functionality to the block - CansteinBerlin/CustomBlocksApi GitHub Wiki
When you create a custom block, you often want your block to have functionality beyond placement and interruption. The CustomBlock class supports many different events that you can listen for. For example, the block being placed, being interacted with, and more. Those events come in the form of methods that you can override in your block class.
Events
A CustomBlockState is passed to all events. This state represents the block in which the event occurred. Most events also provide some additional information about the context in which the event occurred.
OnPlaced (void onPlaced(CustomBlockState, World, Location, @Nullable Player, ItemStack))
The onPlaced event is called after the block is placed in the world. For this reason, it should not be used to set [BlockState properties] or cancel block placement. For that you should use the getPlacementState(ItemPlacementContext) method of the CustomBlock class.
The player might be null, for example if the block is placed using commands.
The ItemStack is the ItemStack used for placing the Block.
OnBreak (boolean onBreak(CustomBlockState, World, Location, Player))
The onBreak event is called before the block is removed from the world. The returning boolean indicates whether the block is broken (false) or the breaking is canceled (true)
OnUse (ActionResult onUse(CustomBlockState, World, Location, Player, EquipmentSlot))
The onUse event is called when a player interacts with the block by right-clicking. This event is called twice for both EquimentSlot.HAND and EquipmentSlot.OFF_HAND.
The returned ActionResult determines what happens to the underlying PlayerInteractEvent. ActionResult.SUCCESS cancels this event and prevents block placement. If ActionResult.FAIL is returned, execution continues normally.
OnDestroyedByExplosion (void onDestroyedByExplosion(CustomBlockState, World, Location))
The OnDestroyedByExplosion event is called when the block is blown up.
OnSteppedOn (void onSteppedOn(CustomBlockState, World, Location, Entity))
The OnStepped event is called when an entity steps on the block. The event only works if the block has a base block and the usesEntityMovementEvent setting of the BlockSettingsBuilder is set to true
OnNeighborUpdate (onNeighborUpdate(CustomBlockState, World, Location, CustomBlock, Location))
The OnNeighborUpdate event is called when this block has been updated. Due to the way Minecraft works, this can happen several times per tick. This event only works if the usesNeighborUpdateEvent setting of the BlockSettingsBuilder is set to true.
The first location is the location of the block where the event is executed. The second location is the location from where the block update was triggered.