Class BlockGrowFeatureEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.LevelEvent
net.neoforged.neoforge.event.level.BlockGrowFeatureEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
public class BlockGrowFeatureEvent
extends LevelEvent
implements net.neoforged.bus.api.ICancellableEvent
This event is fired whenever a block (like a sapling) grows into a feature (like a tree).
In vanilla, this fires for saplings, fungi, mushrooms and azaleas. Mods may fire it for similar blocks.
This event is only fired on the logical server.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.level.LevelEvent
LevelEvent.CreateSpawnPosition, LevelEvent.Load, LevelEvent.PotentialSpawns, LevelEvent.Save, LevelEvent.Unload
-
Field Summary
Modifier and TypeFieldDescriptionprivate @Nullable Holder
<ConfiguredFeature<?, ?>> private final BlockPos
private final RandomSource
-
Constructor Summary
ConstructorDescriptionBlockGrowFeatureEvent
(LevelAccessor level, RandomSource rand, BlockPos pos, @Nullable Holder<ConfiguredFeature<?, ?>> feature) -
Method Summary
Modifier and TypeMethodDescription@Nullable Holder
<ConfiguredFeature<?, ?>> Returns the holder of the feature which will be placed, possibly null.getPos()
Returns the coordinates of the sapling attempting to grow.Returns the random source which initiated the sapling growth.void
setCanceled
(boolean canceled) Canceling this event will prevent the feature from growing.void
setFeature
(@Nullable Holder<ConfiguredFeature<?, ?>> feature) Changes the feature that will be grown.void
setFeature
(ResourceKey<ConfiguredFeature<?, ?>> featureKey) Changes the feature that will be grown.Methods inherited from class net.neoforged.neoforge.event.level.LevelEvent
getLevel
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
-
rand
-
pos
-
feature
-
-
Constructor Details
-
BlockGrowFeatureEvent
public BlockGrowFeatureEvent(LevelAccessor level, RandomSource rand, BlockPos pos, @Nullable @Nullable Holder<ConfiguredFeature<?, ?>> feature)
-
-
Method Details
-
getRandom
Returns the random source which initiated the sapling growth.- Returns:
- the random source which initiated the sapling growth
-
getPos
Returns the coordinates of the sapling attempting to grow.- Returns:
- the coordinates of the sapling attempting to grow
-
getFeature
Returns the holder of the feature which will be placed, possibly null.- Returns:
- the holder of the feature which will be placed, possibly null
-
setFeature
Changes the feature that will be grown. If a null feature is set, the original block will remain in place.- Parameters:
feature
- a Holder referencing a new feature to be placed instead of the current feature.
-
setFeature
Changes the feature that will be grown. If the holder cannot be resolved, a null feature will be set.- Parameters:
featureKey
- a ResourceKey referencing a new feature to be placed instead of the current feature.
-
setCanceled
public void setCanceled(boolean canceled) Canceling this event will prevent the feature from growing. The original block will remain in place.- Specified by:
setCanceled
in interfacenet.neoforged.bus.api.ICancellableEvent
-