Class AlterGroundEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.level.AlterGroundEvent

public class AlterGroundEvent extends net.neoforged.bus.api.Event
This event is fired when AlterGroundDecorator.placeBlockAt(TreeDecorator.Context, BlockPos) attempts to alter a ground block when generating a feature.
An example of this would be large spruce trees converting grass blocks into podzol.

This event is not cancellable.

This event is fired on the main Forge event bus only on the logical server.

This event is fired on worker threads, meaning it is unsafe to access external global state.
Doing so may induce ConcurrentModificationException or deadlocks.

  • Field Details

  • Constructor Details

  • Method Details

    • getContext

      public TreeDecorator.Context getContext()
      Gets the tree decoration context for the current alteration.
    • getPositions

      public List<BlockPos> getPositions()
      The list of positions that are considered roots is different depending on if the context has roots, logs, or both.

      If roots are not present, this list is equivalent to the logs.
      If there are roots, and the roots have the same y-level as the lowest log, both this list is the union of both lists.
      Otherwise, this list is equal to only the roots.

      In either case, only positions which match the y-level of the zeroth element will be used during placement.

      This list is immutable.

      Returns:
      The list of positions that will be used for alteration placement.
    • getStateProvider

      public AlterGroundEvent.StateProvider getStateProvider()
      Gets the current BlockStateProvider that will be used by the AlterGroundDecorator.
      Returns:
      The (possibly event-modified) state provider.
    • setStateProvider

      public void setStateProvider(AlterGroundEvent.StateProvider provider)
      Sets the BlockStateProvider that will be used by the AlterGroundDecorator.
      Because this may be modified by multiple mods, it is advisable to wrap the current provider.

      An example of wrapping the current provider is shown below:

       StateProvider old = event.getStateProvider();
       event.setStateProvider((rand, pos) -> {
           BlockState state = old.getState(rand, pos);
           return state.is(Blocks.PODZOL) ? Blocks.REDSTONE_BLOCK.defaultBlockState() : state;
       });
       
      Parameters:
      provider - The new state provider.