Skip to content

Conversation

@GliczDev
Copy link
Contributor

@GliczDev GliczDev commented Jun 3, 2025

this PR adds two events: BlockPreUseEvent and BlockUsedEvent.

  • BlockPreUseEvent - called before vanilla block use logic, allows to override the result and skip it. (useful when making custom blocks with e.g. noteblocks, allows to proceed to place the block on it)
  • BlockUsedEvent - called after vanilla block use logic, allows to get the final interaction result. (useful when manually placing custom blocks with non-block items, allows to check if the used block already consumed the action, e.g. opened the door)

for more context: events such as these allow making "custom" blocks much, much easier.

for example, "custom" blocks with note blocks:

@EventHandler
public void onBlockPreUse(BlockPreUseEvent event) {
    if (event.getHand() != EquipmentSlot.HAND) return;
    if (event.getBlock().getType() != Material.NOTE_BLOCK) return;

    event.setResultOverride(BlockUseEvent.Result.PASS);
}

which allows block items to be placed like on other blocks.

for placing "custom" blocks, I would later do:

@EventHandler
public void onBlockUsed(BlockUsedEvent event) {
    if (event.getHand() != EquipmentSlot.HAND) return;
    if (event.getResult() != BlockUseEvent.Result.PASS) return;

    // my placement logic
}

this is much easier and more stable than using tons of internals to "simulate" this in PlayerInteractEvent.

@GliczDev GliczDev requested a review from a team as a code owner June 3, 2025 16:11
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Jun 3, 2025
@GliczDev GliczDev force-pushed the block-use-events branch 3 times, most recently from 023fccc to acaa0be Compare June 24, 2025 09:44
@GliczDev GliczDev force-pushed the block-use-events branch from acaa0be to 3b8ef07 Compare July 1, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

1 participant