Package net.minecraftforge.event.world
Class BlockEvent.BlockToolModificationEvent
java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.event.world.BlockEvent
net.minecraftforge.event.world.BlockEvent.BlockToolModificationEvent
- Direct Known Subclasses:
BlockEvent.BlockToolInteractEvent
- Enclosing class:
- BlockEvent
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 world-modifying events are only performed if isSimulated()
returns true
.
This event is Cancelable
. If canceled, this will prevent the tool
from changing the block's state.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.minecraftforge.event.world.BlockEvent
BlockEvent.BlockToolInteractEvent, BlockEvent.BlockToolModificationEvent, BlockEvent.BreakEvent, BlockEvent.CreateFluidSourceEvent, BlockEvent.CropGrowEvent, BlockEvent.EntityMultiPlaceEvent, BlockEvent.EntityPlaceEvent, BlockEvent.FarmlandTrampleEvent, BlockEvent.FluidPlaceBlockEvent, BlockEvent.NeighborNotifyEvent, BlockEvent.PortalSpawnEvent
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 UseOnContext
private final boolean
private BlockState
private final ToolAction
-
Constructor Summary
ConstructorDescriptionBlockToolModificationEvent
(BlockState originalState, UseOnContext context, ToolAction toolAction, boolean simulate) BlockToolModificationEvent
(LevelAccessor level, BlockPos pos, BlockState originalState, ToolAction toolAction) -
Method Summary
Modifier and TypeMethodDescriptionReturns the nullable use on context that this event was performed in.Returns the state to transform the block into after tool use.boolean
Returnstrue
if this event should not perform any actions that modify the world.void
setFinalState
(BlockState finalState) Sets the state to transform the block into after tool use.Methods inherited from class net.minecraftforge.event.world.BlockEvent
getPos, getState, getWorld
Methods inherited from class net.minecraftforge.eventbus.api.Event
getListenerList, getParentListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult, setup
-
Field Details
-
context
-
toolAction
-
simulate
private final boolean simulate -
state
-
-
Constructor Details
-
BlockToolModificationEvent
public BlockToolModificationEvent(BlockState originalState, @Nonnull UseOnContext context, ToolAction toolAction, boolean simulate) -
BlockToolModificationEvent
BlockToolModificationEvent(LevelAccessor level, BlockPos pos, BlockState originalState, ToolAction toolAction)
-
-
Method Details
-
getPlayer
- Returns:
- the player using the tool.
May be null based on what was provided by
the use on context
.
-
getHeldItemStack
- Returns:
- the tool being used
-
getToolAction
- Returns:
- the action being performed
-
isSimulated
public boolean isSimulated()Returnstrue
if this event should not perform any actions that modify the world. Iffalse
, then world-modifying actions can be performed.- Returns:
true
if this event should not perform any actions that modify the world. Iffalse
, then world-modifying actions can be performed.
-
getContext
Returns the nullable use on context that this event was performed in. Starting in 1.19, this will never be null.- Returns:
- the nullable use on context that this event was performed in
-
setFinalState
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
Returns the state to transform the block into after tool use. IfsetFinalState(BlockState)
is not called, this will return the original state. IfEvent.isCanceled()
istrue
, this value will be ignored and the tool action will be canceled.- Returns:
- the state to transform the block into after tool use
-