Minestom/src/main/java/net/minestom/server/instance/block/BlockHandler.java

63 lines
2.2 KiB
Java
Raw Normal View History

2021-05-24 21:39:30 +02:00
package net.minestom.server.instance.block;
2021-05-29 00:55:24 +02:00
import net.minestom.server.entity.Entity;
2021-05-24 22:10:16 +02:00
import net.minestom.server.entity.Player;
import net.minestom.server.instance.Instance;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
2021-06-12 16:02:35 +02:00
/**
* Interface used to provide block behavior. Set with {@link Block#withHandler(BlockHandler)}.
* <p>
* Implementations are expected to be thread safe.
*/
2021-06-12 15:06:52 +02:00
public interface BlockHandler {
2021-05-24 22:10:16 +02:00
/**
* Called when a block has been placed.
*
* @param instance the instance of the block
* @param blockPosition the position of the block
*/
2021-06-12 15:06:52 +02:00
void onPlace(@NotNull Instance instance, @NotNull BlockPosition blockPosition);
2021-05-24 22:10:16 +02:00
/**
* Called when a block has been destroyed or replaced.
*
* @param instance the instance of the block
* @param blockPosition the position of the block
*/
2021-06-12 15:06:52 +02:00
void onDestroy(@NotNull Instance instance, @NotNull BlockPosition blockPosition);
2021-05-24 22:10:16 +02:00
/**
* 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).
*
* @param player the player interacting
* @param hand the hand used to interact
* @param blockPosition the position of this block
* @return true if this block blocks normal item use, false otherwise
*/
2021-06-12 15:06:52 +02:00
boolean onInteract(@NotNull Player player, @NotNull Player.Hand hand, @NotNull BlockPosition blockPosition);
2021-05-24 22:10:16 +02:00
2021-05-29 00:55:24 +02:00
/**
* Defines custom behaviour for entities touching this block.
*
* @param instance the instance
* @param position the position at which the block is
* @param touching the entity currently touching the block
*/
2021-06-12 15:06:52 +02:00
default void handleContact(@NotNull Instance instance, @NotNull BlockPosition position, @NotNull Entity touching) {
2021-05-29 00:55:24 +02:00
}
2021-05-24 22:10:16 +02:00
/**
* Gets the id of this handler.
* <p>
* Used to write the block entity in the anvil world format.
*
* @return the namespace id of this handler
*/
2021-06-12 15:06:52 +02:00
@NotNull NamespaceID getNamespaceId();
2021-05-24 21:39:30 +02:00
}