Class BlockEvent.BlockToolModificationEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.BlockEvent
net.neoforged.neoforge.event.level.BlockEvent.BlockToolModificationEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
- Enclosing class:
BlockEvent
public static class BlockEvent.BlockToolModificationEvent
extends BlockEvent
implements net.neoforged.bus.api.ICancellableEvent
Fired when a block is right-clicked by a tool to change its state.
For example: Used to determine if
an axe can strip
,
a shovel can path
, or a hoe can till
.
Care must be taken to ensure level-modifying events are only performed if isSimulated()
returns false
.
This event is ICancellableEvent
. If canceled, this will prevent the tool
from changing the block's state.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.level.BlockEvent
BlockEvent.BlockToolModificationEvent, BlockEvent.BreakEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final net.minecraft.world.item.context.UseOnContext
private final ItemAbility
private final boolean
private net.minecraft.world.level.block.state.BlockState
-
Constructor Summary
ConstructorsConstructorDescriptionBlockToolModificationEvent
(net.minecraft.world.level.block.state.BlockState originalState, net.minecraft.world.item.context.UseOnContext context, ItemAbility itemAbility, boolean simulate) -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.item.context.UseOnContext
Returns the nonnull use on context that this event was performed in.net.minecraft.world.level.block.state.BlockState
Returns the state to transform the block into after item ability use.net.minecraft.world.item.ItemStack
@Nullable net.minecraft.world.entity.player.Player
boolean
Returnstrue
if this event should not perform any actions that modify the level.void
setFinalState
(@Nullable net.minecraft.world.level.block.state.BlockState finalState) Sets the state to transform the block into after tool use.Methods inherited from class net.neoforged.neoforge.event.level.BlockEvent
getLevel, getPos, getState
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, setCanceled
-
Field Details
-
context
private final net.minecraft.world.item.context.UseOnContext context -
itemAbility
-
simulate
private final boolean simulate -
state
private net.minecraft.world.level.block.state.BlockState state
-
-
Constructor Details
-
BlockToolModificationEvent
public BlockToolModificationEvent(net.minecraft.world.level.block.state.BlockState originalState, net.minecraft.world.item.context.UseOnContext context, ItemAbility itemAbility, boolean simulate)
-
-
Method Details
-
getPlayer
@Nullable public @Nullable net.minecraft.world.entity.player.Player getPlayer()- Returns:
- the player using the tool.
May be null based on what was provided by
the use on context
.
-
getHeldItemStack
public net.minecraft.world.item.ItemStack getHeldItemStack()- Returns:
- the tool being used
-
getItemAbility
- Returns:
- the ability being performed
-
isSimulated
public boolean isSimulated()Returnstrue
if this event should not perform any actions that modify the level. Iffalse
, then level-modifying actions can be performed.- Returns:
true
if this event should not perform any actions that modify the level. Iffalse
, then level-modifying actions can be performed.
-
getContext
public net.minecraft.world.item.context.UseOnContext getContext()Returns the nonnull use on context that this event was performed in.- Returns:
- the nonnull use on context that this event was performed in
-
setFinalState
public void setFinalState(@Nullable @Nullable net.minecraft.world.level.block.state.BlockState finalState) Sets the state to transform the block into after tool use.- Parameters:
finalState
- the state to transform the block into after tool use- See Also:
-
getFinalState
public net.minecraft.world.level.block.state.BlockState getFinalState()Returns the state to transform the block into after item ability use. IfsetFinalState(BlockState)
is not called, this will return the original state. IfICancellableEvent.isCanceled()
istrue
, this value will be ignored and the item ability will be canceled.- Returns:
- the state to transform the block into after tool use
-