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
FieldsModifier and TypeFieldDescriptionprivate net.minecraft.world.InteractionResult
private net.minecraft.world.phys.BlockHitResult
private net.minecraft.util.TriState
private net.minecraft.util.TriState
-
Constructor Summary
ConstructorsConstructorDescriptionRightClickBlock
(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos, net.minecraft.world.phys.BlockHitResult hitVec) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.InteractionResult
net.minecraft.world.phys.BlockHitResult
net.minecraft.util.TriState
net.minecraft.util.TriState
void
setCanceled
(boolean canceled) void
setCancellationResult
(net.minecraft.world.InteractionResult result) 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
(net.minecraft.util.TriState triggerBlock) FALSE:invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
void
setUseItem
(net.minecraft.util.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
private net.minecraft.world.InteractionResult cancellationResult -
useBlock
private net.minecraft.util.TriState useBlock -
useItem
private net.minecraft.util.TriState useItem -
hitVec
private net.minecraft.world.phys.BlockHitResult hitVec
-
-
Constructor Details
-
RightClickBlock
public RightClickBlock(net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.core.BlockPos pos, net.minecraft.world.phys.BlockHitResult hitVec)
-
-
Method Details
-
getUseBlock
public net.minecraft.util.TriState getUseBlock()- Returns:
- If
invalid reference
Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)
-
getUseItem
public net.minecraft.util.TriState getUseItem()- Returns:
- If
IItemExtension.onItemUseFirst(net.minecraft.world.item.ItemStack, net.minecraft.world.item.context.UseOnContext)
andItem.useOn(UseOnContext)
should be called
-
getHitVec
public net.minecraft.world.phys.BlockHitResult getHitVec()- Returns:
- The ray trace result targeting the block.
-
setUseBlock
public void setUseBlock(net.minecraft.util.TriState triggerBlock) 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
public void setUseItem(net.minecraft.util.TriState triggerItem) 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
public net.minecraft.world.InteractionResult 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
public void setCancellationResult(net.minecraft.world.InteractionResult result) Set the InteractionResult that will be returned to vanilla if the event is cancelled, instead of calling the relevant method of the event.
-