Interface BlockHandler

All Known Implementing Classes:
BlockHandler.Dummy

public interface BlockHandler
Interface used to provide block behavior. Set with Block.withHandler(BlockHandler).

Implementations are expected to be thread safe.

  • Method Details

    • onPlace

      default void onPlace(@NotNull @NotNull BlockHandler.Placement placement)
      Called when a block has been placed.
      Parameters:
      placement - the placement details
    • onDestroy

      default void onDestroy(@NotNull @NotNull BlockHandler.Destroy destroy)
      Called when a block has been destroyed or replaced.
      Parameters:
      destroy - the destroy details
    • onInteract

      default boolean onInteract(@NotNull @NotNull BlockHandler.Interaction interaction)
      Handles interactions with this block. Can also block normal item use (containers should block when opening the menu, this prevents the player from placing a block when opening it for instance).
      Parameters:
      interaction - the interaction details
      Returns:
      true to let the block interaction happens, false to cancel
    • onTouch

      default void onTouch(@NotNull @NotNull BlockHandler.Touch touch)
      Defines custom behaviour for entities touching this block.
      Parameters:
      touch - the contact details
    • tick

      default void tick(@NotNull @NotNull BlockHandler.Tick tick)
    • isTickable

      default boolean isTickable()
    • getBlockEntityTags

      @NotNull default @NotNull Collection<Tag<?>> getBlockEntityTags()
      Specifies which block entity tags should be sent to the player.
      Returns:
      The list of tags from this block's block entity that should be sent to the player
      See Also:
    • getBlockEntityAction

      default byte getBlockEntityAction()
    • getNamespaceId

      @NotNull @NotNull NamespaceID getNamespaceId()
      Gets the id of this handler.

      Used to write the block entity in the anvil world format.

      Returns:
      the namespace id of this handler