Class PlayerInteractEvent.LeftClickBlock
java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.event.entity.EntityEvent
net.minecraftforge.event.entity.living.LivingEvent
net.minecraftforge.event.entity.player.PlayerEvent
net.minecraftforge.event.entity.player.PlayerInteractEvent
net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock
- Enclosing class:
- PlayerInteractEvent
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.minecraftforge.eventbus.api.Event.Result)
and setUseItem(net.minecraftforge.eventbus.api.Event.Result)
have no effect.-
Nested Class Summary
Nested classes/interfaces inherited from class net.minecraftforge.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.minecraftforge.event.entity.player.PlayerEvent
PlayerEvent.BreakSpeed, PlayerEvent.Clone, PlayerEvent.HarvestCheck, PlayerEvent.ItemCraftedEvent, PlayerEvent.ItemPickupEvent, 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.minecraftforge.event.entity.living.LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingTickEvent, LivingEvent.LivingVisibilityEvent
Nested classes/interfaces inherited from class net.minecraftforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing
Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event
net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
-
Field Summary
Modifier and TypeFieldDescriptionprivate final PlayerInteractEvent.LeftClickBlock.Action
private net.minecraftforge.eventbus.api.Event.Result
private net.minecraftforge.eventbus.api.Event.Result
-
Constructor Summary
ConstructorDescriptionLeftClickBlock
(Player player, BlockPos pos, Direction face) Deprecated, for removal: This API element is subject to removal in a future version.LeftClickBlock
(Player player, BlockPos pos, Direction face, PlayerInteractEvent.LeftClickBlock.Action action) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraftforge.eventbus.api.Event.Result
net.minecraftforge.eventbus.api.Event.Result
void
setCanceled
(boolean canceled) void
setUseBlock
(net.minecraftforge.eventbus.api.Event.Result triggerBlock) void
setUseItem
(net.minecraftforge.eventbus.api.Event.Result triggerItem) Methods inherited from class net.minecraftforge.event.entity.player.PlayerInteractEvent
getCancellationResult, getFace, getHand, getItemStack, getLevel, getPos, getSide, setCancellationResult
Methods inherited from class net.minecraftforge.event.entity.player.PlayerEvent
getEntity
Methods inherited from class net.minecraftforge.eventbus.api.Event
getListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setPhase, setResult
-
Field Details
-
useBlock
private net.minecraftforge.eventbus.api.Event.Result useBlock -
useItem
private net.minecraftforge.eventbus.api.Event.Result useItem -
action
-
-
Constructor Details
-
LeftClickBlock
@Deprecated(since="1.20.1", forRemoval=true) public LeftClickBlock(Player player, BlockPos pos, Direction face) Deprecated, for removal: This API element is subject to removal in a future version. -
LeftClickBlock
@Internal public LeftClickBlock(Player player, BlockPos pos, Direction face, PlayerInteractEvent.LeftClickBlock.Action action)
-
-
Method Details
-
getUseBlock
public net.minecraftforge.eventbus.api.Event.Result getUseBlock()- Returns:
- If
BlockBehaviour.attack(BlockState, Level, BlockPos, Player)
should be called. Changing this has no effect in creative mode
-
getUseItem
public net.minecraftforge.eventbus.api.Event.Result 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
public void setUseBlock(net.minecraftforge.eventbus.api.Event.Result triggerBlock) -
setUseItem
public void setUseItem(net.minecraftforge.eventbus.api.Event.Result triggerItem) -
setCanceled
public void setCanceled(boolean canceled) - Overrides:
setCanceled
in classnet.minecraftforge.eventbus.api.Event
-