Package org.bukkit

# Interface RegionAccessor

All Superinterfaces:
  `net.kyori.adventure.key.Keyed`, `Keyed`

All Known Subinterfaces:
  `LimitedRegion`, `World`

public interface RegionAccessor extends Keyed
A RegionAccessor gives access to getting, modifying and spawning `Biome`, `BlockState` and `Entity`, as well as generating some basic structures.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType type)`
Creates a tree at the given `Location`
`boolean`
`generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType type, @Nullable Predicate<BlockState> statePredicate)`
Creates a tree at the given `Location`
`boolean`
`generateTree(@NotNull Location location, @NotNull Random random, @NotNull TreeType type, @Nullable Consumer<BlockState> stateConsumer)`
Creates a tree at the given `Location`
`@NotNull Biome`
`getBiome(int x, int y, int z)`
Gets the `Biome` at the given coordinates.
`@NotNull Biome`
`getBiome(@NotNull Location location)`
Gets the `Biome` at the given `Location`.
`@NotNull BlockData`
`getBlockData(int x, int y, int z)`
Gets the `BlockData` at the given coordinates.
`@NotNull BlockData`
`getBlockData(@NotNull Location location)`
Gets the `BlockData` at the given `Location`.
`@NotNull BlockState`
`getBlockState(int x, int y, int z)`
Gets the `BlockState` at the given coordinates.
`@NotNull BlockState`
`getBlockState(@NotNull Location location)`
Gets the `BlockState` at the given `Location`.
`@NotNull Biome`
`getComputedBiome(int x, int y, int z)`
Gets the computed `Biome` at the given coordinates.
`@NotNull List<Entity>`
`getEntities()`
Get a list of all entities in this RegionAccessor
`<T extends Entity>
@NotNull Collection<T>`
`getEntitiesByClass(@NotNull Class<T> cls)`
Get a collection of all entities in this RegionAccessor matching the given class/interface
`@NotNull Collection<Entity>`
`getEntitiesByClasses(@NotNull Class<?>... classes)`
Get a collection of all entities in this RegionAccessor matching any of the given classes/interfaces
`@NotNull NamespacedKey`
`getKey()`
Get the world's key
`@NotNull List<LivingEntity>`
`getLivingEntities()`
Get a list of all living entities in this RegionAccessor
`MoonPhase`
`getMoonPhase()`
`@NotNull Material`
`getType(int x, int y, int z)`
Gets the type of the block at the given coordinates.
`@NotNull Material`
`getType(@NotNull Location location)`
Gets the type of the block at the given `Location`.
`boolean`
`hasCollisionsIn(BoundingBox boundingBox)`
Checks if the world collides with the given boundingbox.
`boolean`
`lineOfSightExists(@NotNull Location from, @NotNull Location to)`
Tell whether a line of sight exists between the given locations
`void`
`setBiome(int x, int y, int z, @NotNull Biome biome)`
Sets the `Biome` for the given block coordinates
`void`
`setBiome(@NotNull Location location, @NotNull Biome biome)`
Sets the `Biome` at the given `Location`.
`void`
`setBlockData(int x, int y, int z, @NotNull BlockData blockData)`
Sets the `BlockData` at the given coordinates.
`void`
`setBlockData(@NotNull Location location, @NotNull BlockData blockData)`
Sets the `BlockData` at the given `Location`.
`void`
`setType(int x, int y, int z, @NotNull Material material)`
Sets the `Material` at the given coordinates.
`void`
`setType(@NotNull Location location, @NotNull Material material)`
Sets the `Material` at the given `Location`.
`<T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz)`
Spawn an entity of a specific class at the given `Location`
`<T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz, boolean randomizeData, @Nullable Consumer<T> function)`
Creates a new entity at the given `Location` with the supplied function run before the entity is added to the world.
`default <T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz, @Nullable Consumer<T> function)`
Spawn an entity of a specific class at the given `Location`, with the supplied function run before the entity is added to the world.
`<T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz, @Nullable Consumer<T> function, CreatureSpawnEvent.SpawnReason reason)`
`default <T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz, CreatureSpawnEvent.SpawnReason reason)`
`default <T extends Entity>
T`
`spawn(@NotNull Location location, @NotNull Class<T> clazz, CreatureSpawnEvent.SpawnReason reason, @Nullable Consumer<T> function)`
`@NotNull Entity`
`spawnEntity(@NotNull Location location, @NotNull EntityType type)`
Creates a entity at the given `Location`
`@NotNull Entity`
`spawnEntity(@NotNull Location loc, @NotNull EntityType type, boolean randomizeData)`
Creates a new entity at the given `Location`.
`default @NotNull Entity`
`spawnEntity(@NotNull Location loc, EntityType type, CreatureSpawnEvent.SpawnReason reason)`
`default @NotNull Entity`
`spawnEntity(@NotNull Location loc, EntityType type, CreatureSpawnEvent.SpawnReason reason, @Nullable Consumer<Entity> function)`

### Methods inherited from interface org.bukkit.Keyed

`key`

## Method Details

### getBiome

@NotNull @NotNull Biome getBiome(@NotNull @NotNull Location location)
Gets the `Biome` at the given `Location`.

Parameters:
  `location` - the location of the biome
Returns:
  Biome at the given location
See Also:
  - `getComputedBiome(int, int, int)`

### getBiome

@NotNull @NotNull Biome getBiome(int x, int y, int z)
Gets the `Biome` at the given coordinates.

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
Returns:
  Biome at the given coordinates
See Also:
  - `getComputedBiome(int, int, int)`

### getComputedBiome

@NotNull @NotNull Biome getComputedBiome(int x, int y, int z)
Gets the computed `Biome` at the given coordinates.

The computed Biome is the Biome as seen by clients for rendering purposes and in the "F3" debug menu. This is computed by looking at the noise biome at this and surrounding quarts and applying complex math operations.

Most other Biome-related methods named getBiome, setBiome, and similar operate on the "noise biome", which is stored per-quart, or in other words, 1 Biome per 4x4x4 block region. This is how Biomes are currently generated and stored on disk.

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
Returns:
  Biome at the given coordinates

### setBiome

void setBiome(@NotNull @NotNull Location location, @NotNull @NotNull Biome biome)
Sets the `Biome` at the given `Location`.

Parameters:
  `location` - the location of the biome
  `biome` - New Biome type for this block

### setBiome

void setBiome(int x, int y, int z, @NotNull @NotNull Biome biome)
Sets the `Biome` for the given block coordinates

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
  `biome` - New Biome type for this block

### getBlockState

@NotNull @NotNull BlockState getBlockState(@NotNull @NotNull Location location)
Gets the `BlockState` at the given `Location`.

Parameters:
  `location` - The location of the block state
Returns:
  Block state at the given location

### getBlockState

@NotNull @NotNull BlockState getBlockState(int x, int y, int z)
Gets the `BlockState` at the given coordinates.

Parameters:
  `x` - X-coordinate of the block state
  `y` - Y-coordinate of the block state
  `z` - Z-coordinate of the block state
Returns:
  Block state at the given coordinates

### getBlockData

@NotNull @NotNull BlockData getBlockData(@NotNull @NotNull Location location)
Gets the `BlockData` at the given `Location`.

Parameters:
  `location` - The location of the block data
Returns:
  Block data at the given location

### getBlockData

@NotNull @NotNull BlockData getBlockData(int x, int y, int z)
Gets the `BlockData` at the given coordinates.

Parameters:
  `x` - X-coordinate of the block data
  `y` - Y-coordinate of the block data
  `z` - Z-coordinate of the block data
Returns:
  Block data at the given coordinates

### getType

@NotNull @NotNull Material getType(@NotNull @NotNull Location location)
Gets the type of the block at the given `Location`.

Parameters:
  `location` - The location of the block
Returns:
  Material at the given coordinates

### getType

@NotNull @NotNull Material getType(int x, int y, int z)
Gets the type of the block at the given coordinates.

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
Returns:
  Material at the given coordinates

### setBlockData

void setBlockData(@NotNull @NotNull Location location, @NotNull @NotNull BlockData blockData)
Sets the `BlockData` at the given `Location`.

Parameters:
  `location` - The location of the block
  `blockData` - The block data to set the block to

### setBlockData

void setBlockData(int x, int y, int z, @NotNull @NotNull BlockData blockData)
Sets the `BlockData` at the given coordinates.

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
  `blockData` - The block data to set the block to

### setType

void setType(@NotNull @NotNull Location location, @NotNull @NotNull Material material)
Sets the `Material` at the given `Location`.

Parameters:
  `location` - The location of the block
  `material` - The type to set the block to

### setType

void setType(int x, int y, int z, @NotNull @NotNull Material material)
Sets the `Material` at the given coordinates.

Parameters:
  `x` - X-coordinate of the block
  `y` - Y-coordinate of the block
  `z` - Z-coordinate of the block
  `material` - The type to set the block to

### generateTree

boolean generateTree(@NotNull @NotNull Location location, @NotNull @NotNull Random random, @NotNull @NotNull TreeType type)
Creates a tree at the given `Location`

Parameters:
  `location` - Location to spawn the tree
  `random` - Random to use to generated the tree
  `type` - Type of the tree to create
Returns:
  true if the tree was created successfully, otherwise false

### generateTree

boolean generateTree(@NotNull @NotNull Location location, @NotNull @NotNull Random random, @NotNull @NotNull TreeType type, @Nullable @Nullable Consumer<BlockState> stateConsumer)
Creates a tree at the given `Location`

The provided consumer gets called for every block which gets changed as a result of the tree generation. When the consumer gets called no modifications to the world are done yet. Which means, that calling `getBlockState(Location)` in the consumer while return the state of the block before the generation.

Modifications done to the `BlockState` in the consumer are respected, which means that it is not necessary to call `BlockState.update()`

Parameters:
  `location` - Location to spawn the tree
  `random` - Random to use to generated the tree
  `type` - Type of the tree to create
  `stateConsumer` - The consumer which should get called for every block which gets changed
Returns:
  true if the tree was created successfully, otherwise false

### generateTree

boolean generateTree(@NotNull @NotNull Location location, @NotNull @NotNull Random random, @NotNull @NotNull TreeType type, @Nullable @Nullable Predicate<BlockState> statePredicate)
Creates a tree at the given `Location`

The provided predicate gets called for every block which gets changed as a result of the tree generation. When the predicate gets called no modifications to the world are done yet. Which means, that calling `getBlockState(Location)` in the predicate will return the state of the block before the generation.

If the predicate returns `true` the block gets set in the world. If it returns `false` the block won't get set in the world.

Parameters:
  `location` - Location to spawn the tree
  `random` - Random to use to generated the tree
  `type` - Type of the tree to create
  `statePredicate` - The predicate which should get used to test if a block should be set or not.
Returns:
  true if the tree was created successfully, otherwise false

### spawnEntity

@NotNull @NotNull Entity spawnEntity(@NotNull @NotNull Location location, @NotNull @NotNull EntityType type)
Creates a entity at the given `Location`

Parameters:
  `location` - The location to spawn the entity
  `type` - The entity to spawn
Returns:
  Resulting Entity of this method

### spawnEntity

@NotNull @NotNull Entity spawnEntity(@NotNull @NotNull Location loc, @NotNull @NotNull EntityType type, boolean randomizeData)
Creates a new entity at the given `Location`.

Parameters:
  `loc` - the location at which the entity will be spawned.
  `type` - the entity type that determines the entity to spawn.
  `randomizeData` - whether or not the entity's data should be randomised before spawning. By default entities are randomised before spawning in regards to their equipment, age, attributes, etc. An example of this randomization would be the color of a sheep, random enchantments on the equipment of mobs or even a zombie becoming a chicken jockey. If set to false, the entity will not be randomised before spawning, meaning all their data will remain in their default state and not further modifications to the entity will be made. Notably only entities that extend the `Mob` interface provide randomisation logic for their spawn. This parameter is hence useless for any other type of entity.
Returns:
  the spawned entity instance.

### getEntities

@NotNull @NotNull List<Entity> getEntities()
Get a list of all entities in this RegionAccessor

Returns:
  A List of all Entities currently residing in this world accessor

### getLivingEntities

@NotNull @NotNull List<LivingEntity> getLivingEntities()
Get a list of all living entities in this RegionAccessor

Returns:
  A List of all LivingEntities currently residing in this world accessor

### getEntitiesByClass

@NotNull <T extends Entity> @NotNull Collection<T> getEntitiesByClass(@NotNull @NotNull Class<T> cls)
Get a collection of all entities in this RegionAccessor matching the given class/interface

Type Parameters:
  `T` - an entity subclass
Parameters:
  `cls` - The class representing the type of entity to match
Returns:
  A List of all Entities currently residing in this world accessor that match the given class/interface

### getEntitiesByClasses

@NotNull @NotNull Collection<Entity> getEntitiesByClasses(@NotNull @NotNull Class<?>... classes)
Get a collection of all entities in this RegionAccessor matching any of the given classes/interfaces

Parameters:
  `classes` - The classes representing the types of entity to match
Returns:
  A List of all Entities currently residing in this world accessor that match one or more of the given classes/interfaces

### spawn

@NotNull <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz) throws IllegalArgumentException
Spawn an entity of a specific class at the given `Location`

Type Parameters:
  `T` - the class of the `Entity` to spawn
Parameters:
  `location` - the `Location` to spawn the entity at
  `clazz` - the class of the `Entity` to spawn
Returns:
  an instance of the spawned `Entity`
Throws:
  `IllegalArgumentException` - if either parameter is null or the `Entity` requested cannot be spawned

### spawn

@NotNull default <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz, @Nullable @Nullable Consumer<T> function) throws IllegalArgumentException
Spawn an entity of a specific class at the given `Location`, with the supplied function run before the entity is added to the world.
Note that when the function is run, the entity will not be actually in the world. Any operation involving such as teleporting the entity is undefined until after this function returns.

Type Parameters:
  `T` - the class of the `Entity` to spawn
Parameters:
  `location` - the `Location` to spawn the entity at
  `clazz` - the class of the `Entity` to spawn
  `function` - the function to be run before the entity is spawned.
Returns:
  an instance of the spawned `Entity`
Throws:
  `IllegalArgumentException` - if either parameter is null or the `Entity` requested cannot be spawned

### spawn

@NotNull default <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz, @NotNull CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### spawn

@NotNull default <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz, @NotNull CreatureSpawnEvent.SpawnReason reason, @Nullable @Nullable Consumer<T> function) throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### spawnEntity

@NotNull default @NotNull Entity spawnEntity(@NotNull @NotNull Location loc, @NotNull EntityType type, @NotNull CreatureSpawnEvent.SpawnReason reason)

### spawnEntity

@NotNull default @NotNull Entity spawnEntity(@NotNull @NotNull Location loc, @NotNull EntityType type, @NotNull CreatureSpawnEvent.SpawnReason reason, @Nullable @Nullable Consumer<Entity> function)

### spawn

@NotNull <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz, @Nullable @Nullable Consumer<T> function, @NotNull CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException

Throws:
  `IllegalArgumentException`

### spawn

@NotNull <T extends Entity> T spawn(@NotNull @NotNull Location location, @NotNull @NotNull Class<T> clazz, boolean randomizeData, @Nullable @Nullable Consumer<T> function) throws IllegalArgumentException
Creates a new entity at the given `Location` with the supplied function run before the entity is added to the world.
Note that when the function is run, the entity will not be actually in the world. Any operation involving such as teleporting the entity is undefined until after this function returns. The passed function however is run after the potential entity's spawn randomization and hence already allows access to the values of the mob, whether or not those were randomized, such as attributes or the entity equipment.

Type Parameters:
  `T` - the generic type of the entity that is being created.
Parameters:
  `location` - the location at which the entity will be spawned.
  `clazz` - the class of the `Entity` that is to be spawned.
  `randomizeData` - whether or not the entity's data should be randomised before spawning. By default entities are randomised before spawning in regards to their equipment, age, attributes, etc. An example of this randomization would be the color of a sheep, random enchantments on the equipment of mobs or even a zombie becoming a chicken jockey. If set to false, the entity will not be randomised before spawning, meaning all their data will remain in their default state and not further modifications to the entity will be made. Notably only entities that extend the `Mob` interface provide randomisation logic for their spawn. This parameter is hence useless for any other type of entity.
  `function` - the function to be run before the entity is spawned.
Returns:
  the spawned entity instance.
Throws:
  `IllegalArgumentException` - if either the world or clazz parameter are null.

### getMoonPhase

@NotNull MoonPhase getMoonPhase()

Returns:
  the current moon phase at the current time in the world

### getKey

@NotNull @NotNull NamespacedKey getKey()
Get the world's key

Specified by:
  `getKey` in interface `Keyed`
Returns:
  the world's key

### lineOfSightExists

boolean lineOfSightExists(@NotNull @NotNull Location from, @NotNull @NotNull Location to)
Tell whether a line of sight exists between the given locations

Parameters:
  `from` - Location to start at
  `to` - target Location
Returns:
  whether a line of sight exists between `from` and `to`

### hasCollisionsIn

boolean hasCollisionsIn(@NotNull BoundingBox boundingBox)
Checks if the world collides with the given boundingbox. This will check for any colliding hard entities (boats, shulkers) / worldborder / blocks. Does not load chunks that are within the bounding box.

Parameters:
  `boundingBox` - the box to check collisions in
Returns:
  collides or not