Class PlayerInteractEvent.RightClickBlock
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.player.PlayerEvent
net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
net.neoforged.neoforge.event.entity.player.PlayerInteractEvent.RightClickBlock
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
- Enclosing class:
PlayerInteractEvent
public static class PlayerInteractEvent.RightClickBlock
extends PlayerInteractEvent
implements net.neoforged.bus.api.ICancellableEvent
This event is fired on both sides whenever the player right clicks while targeting a block.
This event controls which of
,
and
Canceling the event will cause none of the above three to be called.
Let result be the first non-pass return value of the above three methods, or pass, if they all pass.
Or
If result equals
There are various results to this event, see the getters below.
Note that handling things differently on the client vs server may cause desynchronizations!
This event controls which of
IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
,
invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
Item.useOn(UseOnContext)
will be called. Canceling the event will cause none of the above three to be called.
Let result be the first non-pass return value of the above three methods, or pass, if they all pass.
Or
cancellationResult
if the event is cancelled. If result equals
InteractionResult.PASS
, we proceed to PlayerInteractEvent.RightClickItem
. There are various results to this event, see the getters below.
Note that handling things differently on the client vs server may cause desynchronizations!
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
PlayerInteractEvent.EntityInteract, PlayerInteractEvent.EntityInteractSpecific, PlayerInteractEvent.LeftClickBlock, PlayerInteractEvent.LeftClickEmpty, PlayerInteractEvent.RightClickBlock, PlayerInteractEvent.RightClickEmpty, PlayerInteractEvent.RightClickItem
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemSmeltedEvent, PlayerEvent.LoadFromFile, PlayerEvent.NameFormat, PlayerEvent.PlayerChangedDimensionEvent, PlayerEvent.PlayerChangeGameModeEvent, PlayerEvent.PlayerLoggedInEvent, PlayerEvent.PlayerLoggedOutEvent, PlayerEvent.PlayerRespawnEvent, PlayerEvent.SaveToFile, PlayerEvent.StartTracking, PlayerEvent.StopTracking, PlayerEvent.TabListNameFormat
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
Modifier and TypeFieldDescriptionprivate InteractionResult
private BlockHitResult
private TriState
private TriState
-
Constructor Summary
ConstructorDescriptionRightClickBlock
(Player player, InteractionHand hand, BlockPos pos, BlockHitResult hitVec) -
Method Summary
Modifier and TypeMethodDescriptionvoid
setCanceled
(boolean canceled) void
Set the InteractionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event.void
setUseBlock
(TriState triggerBlock) FALSE:invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
void
setUseItem
(TriState triggerItem) FALSE: NeitherItem.useOn(UseOnContext)
orIItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
will be called.Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerInteractEvent
getFace, getHand, getItemStack, getLevel, getPos, getSide
Methods inherited from class net.neoforged.neoforge.event.entity.player.PlayerEvent
getEntity
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.neoforged.bus.api.ICancellableEvent
isCanceled
-
Field Details
-
cancellationResult
-
useBlock
-
useItem
-
hitVec
-
-
Constructor Details
-
RightClickBlock
-
-
Method Details
-
getUseBlock
- Returns:
- If
invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
-
getUseItem
- Returns:
- If
IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
andItem.useOn(UseOnContext)
should be called
-
getHitVec
- Returns:
- The ray trace result targeting the block.
-
setUseBlock
FALSE:invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
DEFAULT:invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
passes.
Note that default activation can be blocked if the user is sneaking and holding an item that does not return true toIItemExtension.doesSneakBypassUse(net.minecraft.world.item.ItemStack, net.minecraft.world.level.LevelReader, net.minecraft.core.BlockPos, net.minecraft.world.entity.player.Player)
.
TRUE:Block.updateOrDestroy(BlockState, BlockState, LevelAccessor, BlockPos, int, int)
will always be called, unlessIItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
does not pass. -
setUseItem
FALSE: NeitherItem.useOn(UseOnContext)
orIItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
will be called.
DEFAULT:IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
will always be called, andItem.useOn(UseOnContext)
will be called if the block passes.
TRUE:IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
will always be called, andItem.useOn(UseOnContext)
will be called if the block passes, regardless of cooldowns or emptiness. -
setCanceled
public void setCanceled(boolean canceled) - Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-
getCancellationResult
- Returns:
- 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 is
InteractionResult.PASS
, meaning cancelled events will cause the client to keep trying more interactions until something works.
-
setCancellationResult
Set the InteractionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event.
-