Package commoble.useitemonblockevent.api

# Class UseItemOnBlockEvent

java.lang.Object
net.minecraftforge.eventbus.api.Event
commoble.useitemonblockevent.api.UseItemOnBlockEvent

public final class UseItemOnBlockEvent extends net.minecraftforge.eventbus.api.Event
Event that provides fine-grained control over what happens when an item is used on a block.
This event called on both the client and server threads when an item is used on a block.
Cancelling the event with `cancelWithResult(net.minecraft.world.InteractionResult)` will prevent the item/block's use-item-on-block logic from running.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`UseItemOnBlockEvent.UsePhase`

## Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event

`net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result`

## Constructor Summary

Constructors
Constructor
Description
`UseItemOnBlockEvent(net.minecraft.world.item.context.UseOnContext context, UseItemOnBlockEvent.UsePhase usePhase)`

## Method Summary

Modifier and Type
Method
Description
`void`
`cancelWithResult(net.minecraft.world.InteractionResult result)`
Cancels the use interaction (preventing the item from being used) and provides the specified result to the interaction logic instead.
`net.minecraft.world.InteractionResult`
`getCancellationResult()`
`net.minecraft.world.item.context.UseOnContext`
`getUseOnContext()`
`UseItemOnBlockEvent.UsePhase`
`getUsePhase()`

### Methods inherited from class net.minecraftforge.eventbus.api.Event

`getListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### UseItemOnBlockEvent

public UseItemOnBlockEvent(net.minecraft.world.item.context.UseOnContext context, UseItemOnBlockEvent.UsePhase usePhase)

## Method Details

### getUseOnContext

public net.minecraft.world.item.context.UseOnContext getUseOnContext()

Returns:
  context

### getUsePhase

public UseItemOnBlockEvent.UsePhase getUsePhase()

Returns:
  The Use Phase of the interaction, see `UseItemOnBlockEvent.UsePhase` for semantics

### cancelWithResult

public void cancelWithResult(net.minecraft.world.InteractionResult result)
Cancels the use interaction (preventing the item from being used) and provides the specified result to the interaction logic instead.

Parameters:
  `result` - The interaction result to return to the interaction logic.
  - SUCCESS, CONSUME, CONSUME_PARTIAL, and FAIL will prevent further types of interaction attempts when provided from the PRE_BLOCK phase.
  - SUCCESS, CONSUME, and CONSUME_PARTIAL will trigger advancements on the server (except in the PRE_BLOCK phase), and will also prevent the POST_BLOCK item interaction from occurring if provided during the BLOCK phase.
  - SUCCESS will trigger the arm-swinging mechanic.
  - PASS will always allow proceeding to the next phase.

### getCancellationResult

public net.minecraft.world.InteractionResult getCancellationResult()

Returns:
  The result that the canceller cancelled this event with.
  Not meaningful unless and until this event has been cancelled; intended to be used by the event firer.