类 UseItemOnBlockEvent
- 所有已实现的接口:
net.neoforged.bus.api.ICancellableEvent
The event fires in three phases, corresponding with the three interaction behaviors:
IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
,
BlockBehaviour.useItemOn(net.minecraft.world.item.ItemStack, net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.Level, net.minecraft.core.BlockPos, net.minecraft.world.entity.player.Player, net.minecraft.world.InteractionHand, net.minecraft.world.phys.BlockHitResult)
,
and Item.useOn(net.minecraft.world.item.context.UseOnContext)
.
The event fires after the interaction logic decides to run the particular interaction behavior,
as opposed to PlayerInteractEvent.RightClickBlock
which fires once-per-right-click, before the behavior-choosing logic.
If the event is cancelled via cancelWithResult(net.minecraft.world.InteractionResult)
,
then the normal interaction behavior for that phase will not run,
and the specified InteractionResult
will be returned instead.
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明private InteractionResult
private final UseOnContext
private final @Nullable Direction
private final InteractionHand
private final ItemStack
private final Level
private final @Nullable Player
private final BlockPos
private final UseItemOnBlockEvent.UsePhase
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明void
cancelWithResult
(InteractionResult result) Cancels the use interaction (preventing the block or item's use behavior from running) and provides the specified result to the interaction logic instead.@Nullable Direction
getFace()
getHand()
getLevel()
@Nullable Player
getPos()
If the interaction was on an entity, will be a BlockPos centered on the entity.net.neoforged.fml.LogicalSide
getSide()
返回 The Use Phase of the interaction。void
Set theInteractionResult
that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 net.neoforged.bus.api.ICancellableEvent
isCanceled, setCanceled
-
字段详细资料
-
level
-
player
-
hand
-
heldItem
-
pos
-
face
-
context
-
usePhase
-
cancellationResult
-
-
构造器详细资料
-
UseItemOnBlockEvent
-
-
方法详细资料
-
getPlayer
- 返回:
- player or null
-
getHand
- 返回:
- The hand involved in this interaction. Will never be null.
-
getItemStack
- 返回:
- The itemstack involved in this interaction,
ItemStack.EMPTY
if the hand was empty.
-
getPos
If the interaction was on an entity, will be a BlockPos centered on the entity. If the interaction was on a block, will be the position of that block. Otherwise, will be a BlockPos centered on the player. Will never be null.- 返回:
- The position involved in this interaction.
-
getFace
- 返回:
- The face involved in this interaction. For all non-block interactions, this will return null.
-
getLevel
- 返回:
- Convenience method to get the level of this interaction.
-
getUseOnContext
- 返回:
- context
-
getUsePhase
返回 The Use Phase of the interaction。- 返回:
- The Use Phase of the interaction
- 另请参阅:
-
getSide
public net.neoforged.fml.LogicalSide getSide()- 返回:
- The effective, i.e. logical, side of this interaction. This will be
LogicalSide.CLIENT
on the client thread, andLogicalSide.SERVER
on the server thread.
-
cancelWithResult
Cancels the use interaction (preventing the block or item's use behavior from running) and provides the specified result to the interaction logic instead.
Invoke this if you intend to prevent the default interaction behavior and replace it with your own.
- 参数:
result
- InteractionResult to return to the interaction logicInteractionResult.SUCCESS
,InteractionResult.CONSUME
, and FAIL will prevent further types of interaction attempts when provided from the ITEM_BEFORE_BLOCK phase.InteractionResult.SUCCESS
,InteractionResult.CONSUME
will trigger advancements on the server (except in the ITEM_BEFORE_BLOCK phase), and will also prevent the ITEM_AFTER_BLOCK item interaction from occurring if provided during the BLOCK phase.InteractionResult.SUCCESS
will trigger the arm-swinging mechanic.InteractionResult.TRY_WITH_EMPTY_HAND
will always allow proceeding to the next phase.InteractionResult.PASS
will not call the block'suse method
-
getCancellationResult
- 返回:
- The
InteractionResult
that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event. By default, this isInteractionResult.TRY_WITH_EMPTY_HAND
, meaning cancelled events will cause the client to keep trying more interactions until something works.
-
setCancellationResult
Set theInteractionResult
that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event.
-