Class PlayerInteractEvent.LeftClickBlock
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.LeftClickBlock
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
- Enclosing class:
PlayerInteractEvent
public static class PlayerInteractEvent.LeftClickBlock
extends PlayerInteractEvent
implements net.neoforged.bus.api.ICancellableEvent
This event is fired when a player left clicks while targeting a block.
This event controls which of
BlockBehaviour.attack(BlockState, Level, BlockPos, Player)
and/or the item harvesting methods will be called
Canceling the event will cause none of the above noted methods to be called.
There are various results to this event, see the getters below.
This event is fired at various points during left clicking on blocks, at both the start and end on the server, and at the start and while held down on the client.
Use getAction()
to check which type of action triggered this event.
Note that if the event is canceled and the player holds down left mouse, the event will continue to fire.
This is due to how vanilla calls the left click handler methods.
Also note that creative mode directly breaks the block without running any other logic.
Therefore, in creative mode, setUseBlock(net.neoforged.neoforge.common.util.TriState)
and setUseItem(net.neoforged.neoforge.common.util.TriState)
have no effect.-
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
-
Constructor Summary
ConstructorDescriptionLeftClickBlock
(Player player, BlockPos pos, Direction face, PlayerInteractEvent.LeftClickBlock.Action action) -
Method Summary
Modifier and TypeMethodDescriptionvoid
setCanceled
(boolean canceled) void
setUseBlock
(TriState triggerBlock) void
setUseItem
(TriState triggerItem) 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
-
useBlock
-
useItem
-
action
-
-
Constructor Details
-
LeftClickBlock
@Internal public LeftClickBlock(Player player, BlockPos pos, Direction face, PlayerInteractEvent.LeftClickBlock.Action action)
-
-
Method Details
-
getUseBlock
- Returns:
- If
BlockBehaviour.attack(BlockState, Level, BlockPos, Player)
should be called. Changing this has no effect in creative mode
-
getUseItem
- Returns:
- If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
-
getAction
- Returns:
- The action type for this interaction. Will never be null.
-
setUseBlock
-
setUseItem
-
setCanceled
public void setCanceled(boolean canceled) - Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-