UseBlockEvent
Package:
com.hypixel.hytale.server.core.event.events.ecsExtends:EcsEventCancellable: No (base class) — see inner classes below
Abstract ECS event dispatched when a player interacts with (uses) a block. Uses a Pre/Post pattern: UseBlockEvent.Pre fires before the interaction and can be cancelled, while UseBlockEvent.Post fires after the interaction has completed.
Fields / Accessors (Base Class)
Section titled “Fields / Accessors (Base Class)”| Field | Type | Accessor | Mutable | Nullable |
|---|---|---|---|---|
interactionType | InteractionType | getInteractionType() | No | No |
context | InteractionContext | getContext() | No | No |
targetBlock | Vector3i | getTargetBlock() | No | No |
blockType | BlockType | getBlockType() | No | No |
- interactionType — The type of interaction being performed on the block.
- context — Additional context about the interaction.
- targetBlock — The world-space coordinates of the block being used.
- blockType — The type of block being interacted with.
UseBlockEvent.Pre
Section titled “UseBlockEvent.Pre”Extends:
UseBlockEventImplements:ICancellableEcsEventCancellable: Yes
Fired before the block interaction takes effect. Cancelling this event prevents the interaction from occurring.
Fired By
Section titled “Fired By”UseBlockInteraction.execute(line 65) viacommandBuffer.invoke(ref, event)— ECS dispatch before block use takes effect.
Listening
Section titled “Listening”public class MyUseBlockPreHandler extends EntityEventSystem<EntityStore, UseBlockEvent.Pre> { @Override public Query<EntityStore> getQuery() { return MY_COMPONENT_TYPE; }
@Override public void handle(int index, ArchetypeChunk<EntityStore> chunk, Store<EntityStore> store, CommandBuffer<EntityStore> commandBuffer, UseBlockEvent.Pre event) { BlockType blockType = event.getBlockType();
// Example: prevent interaction with certain blocks if (blockType == BlockType.LOCKED_CHEST) { event.setCancelled(true); } }}
// Register in plugin setup():getEntityStoreRegistry().registerSystem(new MyUseBlockPreHandler());UseBlockEvent.Post
Section titled “UseBlockEvent.Post”Extends:
UseBlockEventCancellable: No
Fired after the block interaction has completed. This is an informational event — the interaction has already occurred and cannot be undone.
Fired By
Section titled “Fired By”UseBlockInteraction.execute(line 76) viacommandBuffer.invoke(ref, event)— ECS dispatch after block use completes.
Listening
Section titled “Listening”public class MyUseBlockPostHandler extends EntityEventSystem<EntityStore, UseBlockEvent.Post> { @Override public Query<EntityStore> getQuery() { return MY_COMPONENT_TYPE; }
@Override public void handle(int index, ArchetypeChunk<EntityStore> chunk, Store<EntityStore> store, CommandBuffer<EntityStore> commandBuffer, UseBlockEvent.Post event) { BlockType blockType = event.getBlockType(); Vector3i target = event.getTargetBlock();
// Example: log block interactions for analytics logger.info("Block used: {} at {}", blockType, target); }}
// Register in plugin setup():getEntityStoreRegistry().registerSystem(new MyUseBlockPostHandler());Related Events
Section titled “Related Events”BreakBlockEvent— Fired when a block is mined/destroyed, as opposed to interacted with.PlaceBlockEvent— Fired when a block is placed.LivingEntityUseBlockEvent— Deprecated standard-event predecessor.