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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBlockGrowFeatureEvent
(net.minecraft.world.level.LevelAccessor level, net.minecraft.util.RandomSource rand, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> feature) -
Method Summary
Modifier and TypeMethodDescription@Nullable net.minecraft.core.Holder
<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> Returns the holder of the feature which will be placed, possibly null.net.minecraft.core.BlockPos
getPos()
Returns the coordinates of the sapling attempting to grow.net.minecraft.util.RandomSource
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 net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> feature) Changes the feature that will be grown.void
setFeature
(net.minecraft.resources.ResourceKey<net.minecraft.world.level.levelgen.feature.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
private final net.minecraft.util.RandomSource rand -
pos
private final net.minecraft.core.BlockPos pos -
feature
@Nullable private @Nullable net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?,?>> feature
-
-
Constructor Details
-
BlockGrowFeatureEvent
public BlockGrowFeatureEvent(net.minecraft.world.level.LevelAccessor level, net.minecraft.util.RandomSource rand, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> feature)
-
-
Method Details
-
getRandom
public net.minecraft.util.RandomSource getRandom()Returns the random source which initiated the sapling growth.- Returns:
- the random source which initiated the sapling growth
-
getPos
public net.minecraft.core.BlockPos getPos()Returns the coordinates of the sapling attempting to grow.- Returns:
- the coordinates of the sapling attempting to grow
-
getFeature
@Nullable public @Nullable net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?,?>> 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
public void setFeature(@Nullable @Nullable net.minecraft.core.Holder<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> feature) 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
public void setFeature(net.minecraft.resources.ResourceKey<net.minecraft.world.level.levelgen.feature.ConfiguredFeature<?, ?>> featureKey) 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
-