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
Nested ClassesModifier and TypeInterfaceDescriptionstatic classstatic final classHandler used for loaded blocks with unknown namespace in order to do not lose the information while saving, and for runtime debugging purpose.static final classstatic classRepresents an object forwarded toonPlace(Placement).static final classstatic final classstatic final classstatic final class -
Method Summary
Modifier and TypeMethodDescriptiondefault bytedefault @NotNull Collection<Tag<?>> Specifies which block entity tags should be sent to the player.@NotNull NamespaceIDGets the id of this handler.default booleandefault voidonDestroy(@NotNull BlockHandler.Destroy destroy) Called when a block has been destroyed or replaced.default booleanonInteract(@NotNull BlockHandler.Interaction interaction) Handles interactions with this block.default voidonPlace(@NotNull BlockHandler.Placement placement) Called when a block has been placed.default voidonTouch(@NotNull BlockHandler.Touch touch) Defines custom behaviour for entities touching this block.default voidtick(@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
-