Interface CreatureSpawner

All Superinterfaces:
BlockState, Metadatable, PersistentDataHolder, TileState

public interface CreatureSpawner extends TileState
Represents a captured state of a creature spawner.
  • Method Details

    • getSpawnedType

      @Nullable @Nullable EntityType getSpawnedType()
      Get the spawner's creature type.
      Returns:
      The creature type or null if it not set.
    • setSpawnedType

      void setSpawnedType(@Nullable @Nullable EntityType creatureType)
      Set the spawner's creature type.
      This will override any entities that have been added with addPotentialSpawn(org.bukkit.entity.EntitySnapshot, int, org.bukkit.block.spawner.SpawnRule)
      Parameters:
      creatureType - The creature type or null to clear.
    • setCreatureTypeByName

      @Deprecated void setCreatureTypeByName(@Nullable @Nullable String creatureType)
      Deprecated.
      Set the spawner mob type.
      Parameters:
      creatureType - The creature type's name or null to clear.
    • getCreatureTypeName

      @Deprecated @Nullable @Nullable String getCreatureTypeName()
      Deprecated.
      magic value, use getSpawnedType().
      Get the spawner's creature type.
      Returns:
      The creature type's name if is set.
    • getDelay

      int getDelay()
      Get the spawner's delay.
      This is the delay, in ticks, until the spawner will spawn its next mob.
      Returns:
      The delay.
    • setDelay

      void setDelay(int delay)
      Set the spawner's delay.
      If set to -1, the spawn delay will be reset to a random value between getMinSpawnDelay() and getMaxSpawnDelay().
      Parameters:
      delay - The delay.
    • getMinSpawnDelay

      int getMinSpawnDelay()
      The minimum spawn delay amount (in ticks).
      This value is used when the spawner resets its delay (for any reason). It will choose a random number between getMinSpawnDelay() and getMaxSpawnDelay() for its next getDelay().
      Default value is 200 ticks.
      Returns:
      the minimum spawn delay amount
    • setMinSpawnDelay

      void setMinSpawnDelay(int delay)
      Set the minimum spawn delay amount (in ticks).
      Parameters:
      delay - the minimum spawn delay amount
      See Also:
    • getMaxSpawnDelay

      int getMaxSpawnDelay()
      The maximum spawn delay amount (in ticks).
      This value is used when the spawner resets its delay (for any reason). It will choose a random number between getMinSpawnDelay() and getMaxSpawnDelay() for its next getDelay().
      This value must be greater than 0 and less than or equal to getMaxSpawnDelay().
      Default value is 800 ticks.
      Returns:
      the maximum spawn delay amount
    • setMaxSpawnDelay

      void setMaxSpawnDelay(int delay)
      Set the maximum spawn delay amount (in ticks).
      This value must be greater than 0, as well as greater than or equal to getMinSpawnDelay()
      Parameters:
      delay - the new maximum spawn delay amount
      See Also:
    • getSpawnCount

      int getSpawnCount()
      Get how many mobs attempt to spawn.
      Default value is 4.
      Returns:
      the current spawn count
    • setSpawnCount

      void setSpawnCount(int spawnCount)
      Set how many mobs attempt to spawn.
      Parameters:
      spawnCount - the new spawn count
    • getMaxNearbyEntities

      int getMaxNearbyEntities()
      Set the new maximum amount of similar entities that are allowed to be within spawning range of this spawner.
      If more than the maximum number of entities are within range, the spawner will not spawn and try again with a new getDelay().
      Default value is 16.
      Returns:
      the maximum number of nearby, similar, entities
    • setMaxNearbyEntities

      void setMaxNearbyEntities(int maxNearbyEntities)
      Set the maximum number of similar entities that are allowed to be within spawning range of this spawner.
      Similar entities are entities that are of the same EntityType
      Parameters:
      maxNearbyEntities - the maximum number of nearby, similar, entities
    • getRequiredPlayerRange

      int getRequiredPlayerRange()
      Get the maximum distance(squared) a player can be in order for this spawner to be active.
      If this value is less than or equal to 0, this spawner is always active (given that there are players online).
      Default value is 16.
      Returns:
      the maximum distance(squared) a player can be in order for this spawner to be active.
    • setRequiredPlayerRange

      void setRequiredPlayerRange(int requiredPlayerRange)
      Set the maximum distance (squared) a player can be in order for this spawner to be active.
      Setting this value to less than or equal to 0 will make this spawner always active (given that there are players online).
      Parameters:
      requiredPlayerRange - the maximum distance (squared) a player can be in order for this spawner to be active.
    • getSpawnRange

      int getSpawnRange()
      Get the radius around which the spawner will attempt to spawn mobs in.
      This area is square, includes the block the spawner is in, and is centered on the spawner's x,z coordinates - not the spawner itself.
      It is 2 blocks high, centered on the spawner's y-coordinate (its bottom); thus allowing mobs to spawn as high as its top surface and as low as 1 block below its bottom surface.
      Default value is 4.
      Returns:
      the spawn range
    • setSpawnRange

      void setSpawnRange(int spawnRange)
      Set the new spawn range.
      Parameters:
      spawnRange - the new spawn range
      See Also:
    • getSpawnedEntity

      @Nullable @Nullable EntitySnapshot getSpawnedEntity()
      Gets the EntitySnapshot that will be spawned by this spawner or null if no entities have been assigned to this spawner.

      All applicable data from the spawner will be copied, such as custom name, health, and velocity.

      Returns:
      the entity snapshot or null if no entities have been assigned to this spawner.
    • setSpawnedEntity

      void setSpawnedEntity(@NotNull @NotNull EntitySnapshot snapshot)
      Sets the entity that will be spawned by this spawner.
      This will override any previous entries that have been added with addPotentialSpawn(org.bukkit.entity.EntitySnapshot, int, org.bukkit.block.spawner.SpawnRule)

      All applicable data from the snapshot will be copied, such as custom name, health, and velocity.

      Parameters:
      snapshot - the entity snapshot
    • addPotentialSpawn

      void addPotentialSpawn(@NotNull @NotNull EntitySnapshot snapshot, int weight, @Nullable @Nullable SpawnRule spawnRule)
      Adds a new EntitySnapshot to the list of entities this spawner can spawn.

      The weight will determine how often this entry is chosen to spawn, higher weighted entries will spawn more often than lower weighted ones.
      The SpawnRule will determine under what conditions this entry can spawn, passing null will use the default conditions for the given entity.

      Parameters:
      snapshot - the snapshot that will be spawned
      weight - the weight
      spawnRule - the spawn rule for this entity, or null
    • addPotentialSpawn

      void addPotentialSpawn(@NotNull @NotNull SpawnerEntry spawnerEntry)
      Adds a new SpawnerEntry to the list of entities this spawner can spawn.
      Parameters:
      spawnerEntry - the spawner entry to use
      See Also:
    • setPotentialSpawns

      void setPotentialSpawns(@NotNull @NotNull Collection<SpawnerEntry> entries)
      Sets the list of SpawnerEntry this spawner can spawn.
      This will override any previous entries added with addPotentialSpawn(org.bukkit.entity.EntitySnapshot, int, org.bukkit.block.spawner.SpawnRule)
      Parameters:
      entries - the list of entries
    • getPotentialSpawns

      @NotNull @NotNull List<SpawnerEntry> getPotentialSpawns()
      Gets a list of potential spawns from this spawner or an empty list if no entities have been assigned to this spawner.
      Changes made to the returned list will not be reflected in the spawner unless applied with setPotentialSpawns(java.util.Collection<org.bukkit.block.spawner.SpawnerEntry>)
      Returns:
      a list of potential spawns from this spawner, or an empty list if no entities have been assigned to this spawner
      See Also:
    • isActivated

      boolean isActivated()
      Check if spawner is activated (a player is close enough)
      Returns:
      True if a player is close enough to activate it
    • resetTimer

      void resetTimer()
      Resets the spawn delay timer within the min/max range
    • setSpawnedItem

      void setSpawnedItem(@NotNull ItemStack itemStack)
      Sets the EntityType to EntityType.DROPPED_ITEM and sets the data to the given ItemStack.

      setSpawnCount(int) does not dictate the amount of items in the stack spawned, but rather how many stacks should be spawned.

      Parameters:
      itemStack - The item to spawn. Must not be air.
      See Also: