Class LandPathTypeRegistry

java.lang.Object
net.fabricmc.fabric.api.registry.LandPathTypeRegistry

public final class LandPathTypeRegistry extends Object
A registry to associate block states with specific path types. Specifying a path type for a block will change the way an entity recognizes the block when trying to pathfind. You can make a safe block dangerous and vice-versa. This works only for entities that move on air and land. Duplicated registrations for the same block will replace the previous registration entry.
  • Method Details

    • register

      public static void register(net.minecraft.world.level.block.Block block, @Nullable net.minecraft.world.level.pathfinder.PathType pathType, @Nullable net.minecraft.world.level.pathfinder.PathType pathTypeIfNeighbor)
      Registers a PathType for the specified block, overriding the default block behavior.
      Parameters:
      block - Block to register.
      pathType - PathType to associate with the block if it is a direct target in an entity path. (Pass null to not specify a path type and use the default behavior)
      pathTypeIfNeighbor - PathType to associate with the block, if it is in a direct neighbor position to an entity path that is directly next to a block that the entity will pass through or above. (Pass null to not specify a path type and use the default behavior)
    • register

      public static void register(net.minecraft.world.level.block.Block block, LandPathTypeRegistry.StaticPathTypeProvider provider)
      Registers a LandPathTypeRegistry.StaticPathTypeProvider for the specified block overriding the default block behavior.

      A static provider provides the path type basing on the block state.

      Parameters:
      block - Block to register.
      provider - LandPathTypeRegistry.StaticPathTypeProvider to associate with the block.
    • registerDynamic

      public static void registerDynamic(net.minecraft.world.level.block.Block block, LandPathTypeRegistry.DynamicPathTypeProvider provider)
      Registers a LandPathTypeRegistry.DynamicPathTypeProvider for the specified block, overriding the default block behavior.

      A dynamic provider provides the path type basing on the block state, level and position. This is more difficult to handle, must be used only if you want to change the path type basing on the position of the block in the world, and may degrade the game performances because cannot be optimized but must be recalculated at every tick for every entity.

      Parameters:
      block - Block to register.
      provider - LandPathTypeRegistry.DynamicPathTypeProvider to associate with the block.
    • getPathType

      public static @Nullable net.minecraft.world.level.pathfinder.PathType getPathType(net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, boolean neighbor)
      Gets the PathType from the provider registered for the specified block state at the specified position.

      If no valid PathType provider is registered for the block, it returns null. You cannot use this method to retrieve vanilla block path types.

      Parameters:
      state - Current block state.
      level - Current level.
      pos - Current position.
      neighbor - Specifies if the block is not a directly targeted block, but a neighbor block in the path.
      Returns:
      the custom PathType from the provider registered for the specified block, passing the block state, the level, and the position to the provider, or null if no valid provider is registered for the block.
    • getPathTypeProvider

      public static @Nullable LandPathTypeRegistry.PathTypeProvider getPathTypeProvider(net.minecraft.world.level.block.Block block)
      Gets the raw LandPathTypeRegistry.PathTypeProvider registered for the specified block.

      If no LandPathTypeRegistry.PathTypeProvider is registered for the block, it returns null.

      Note 1: LandPathTypeRegistry.PathTypeProvider is a marker interface with no methods, so you need to cast the result to a subtype, in order to get something from it. Currently, if non-null, the result can be of LandPathTypeRegistry.StaticPathTypeProvider or LandPathTypeRegistry.DynamicPathTypeProvider. Note that more kinds of providers might be added if the API is expanded in the future, so make sure not to fail if another type of object is returned.

      Note 2: This method is intended to be used in any cases in which you need to get the raw provider for the block, if you need the PathType for the block state instead, you can simply use getPathType(BlockState, BlockGetter, BlockPos, boolean).

      Parameters:
      block - Current block.
      Returns:
      the LandPathTypeRegistry.PathTypeProvider registered for the specified block, or null if no provider is registered for the block.