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.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static final class
Handler used for loaded blocks with unknown namespace in order to do not lose the information while saving, and for runtime debugging purpose.static final class
static class
Represents an object forwarded toonPlace(Placement)
.static final class
static final class
static final class
static final class
-
Method Summary
Modifier and TypeMethodDescriptiondefault byte
default @NotNull Collection
<Tag<?>> Specifies which block entity tags should be sent to the player.@NotNull NamespaceID
Gets the id of this handler.default boolean
default void
onDestroy
(@NotNull BlockHandler.Destroy destroy) Called when a block has been destroyed or replaced.default boolean
onInteract
(@NotNull BlockHandler.Interaction interaction) Handles interactions with this block.default void
onPlace
(@NotNull BlockHandler.Placement placement) Called when a block has been placed.default void
onTouch
(@NotNull BlockHandler.Touch touch) Defines custom behaviour for entities touching this block.default void
tick
(@NotNull BlockHandler.Tick tick)
-
Method Details
-
onPlace
Called when a block has been placed.- Parameters:
placement
- the placement details
-
onDestroy
Called when a block has been destroyed or replaced.- Parameters:
destroy
- the destroy details
-
onInteract
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
Defines custom behaviour for entities touching this block.- Parameters:
touch
- the contact details
-
tick
-
isTickable
default boolean isTickable() -
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
Gets the id of this handler.Used to write the block entity in the anvil world format.
- Returns:
- the namespace id of this handler
-