Interface ServerLocation

All Superinterfaces:
DataHolder, DataHolder.Mutable, DataSerializable, DirectionRelativeDataHolder, DirectionRelativeDataHolder.Mutable, Location<ServerWorld,ServerLocation>, ValueContainer

A position within a particular ServerWorld.

Locations are immutable. Methods that change the properties of the location create a new instance.

  • Method Details

    • of

      static ServerLocation of(ServerWorld world, double x, double y, double z)
    • of

      static ServerLocation of(ResourceKey worldKey, double x, double y, double z)
    • of

      static ServerLocation of(ServerWorld world, Vector3d position)
    • of

      static ServerLocation of(ResourceKey worldKey, Vector3d position)
    • of

      static ServerLocation of(ServerWorld world, int x, int y, int z)
    • of

      static ServerLocation of(ResourceKey worldKey, int x, int y, int z)
    • of

      static ServerLocation of(ServerWorld world, Vector3i position)
    • of

      static ServerLocation of(ResourceKey worldKey, Vector3i position)
    • worldKey

      ResourceKey worldKey()
      Gets the UUID of the world.
      Returns:
      The world unique id
    • asLocatableBlock

      LocatableBlock asLocatableBlock()
      Returns:
      The locatable block of this location.
    • map

      <T> T map(BiFunction<ServerWorld,Vector3d,T> mapper)
      Calls the mapper function on the world and position.
      Type Parameters:
      T - The return type of the mapper
      Parameters:
      mapper - The mapper
      Returns:
      The results of the mapping
    • mapBlock

      <T> T mapBlock(BiFunction<ServerWorld,Vector3i,T> mapper)
      Calls the mapper function on the world and block position.
      Type Parameters:
      T - The return type of the mapper
      Parameters:
      mapper - The mapper
      Returns:
      The results of the mapping
    • mapChunk

      <T> T mapChunk(BiFunction<ServerWorld,Vector3i,T> mapper)
      Calls the mapper function on the world and chunk position.
      Type Parameters:
      T - The return type of the mapper
      Parameters:
      mapper - The mapper
      Returns:
      The results of the mapping
    • mapBiome

      <T> T mapBiome(BiFunction<ServerWorld,Vector3i,T> mapper)
      Calls the mapper function on the world and biome position.
      Type Parameters:
      T - The return type of the mapper
      Parameters:
      mapper - The mapper
      Returns:
      The results of the mapping
    • restoreSnapshot

      boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag)
      Replace the block at this position with a copy of the given snapshot.

      Changing the snapshot afterwards will not affect the block that has been placed at this location.

      Parameters:
      snapshot - The snapshot
      force - If true, forces block state to be set even if the BlockType does not match the snapshot one.
      flag - The various change flags controlling some interactions
      Returns:
      True if the snapshot restore was successful
    • removeBlock

      boolean removeBlock()
      Remove the block at this position by replacing it with BlockTypes.AIR.

      This will remove any extended block data at the given position.

      Returns:
      True if the block change was successful
    • createEntity

      <E extends Entity> E createEntity(EntityType<E> type)
      Create an entity instance at the given position.

      Creating an entity does not spawn the entity into the world. An entity created means the entity can be spawned at the given location. If Optional.empty() was returned, the entity is not able to spawn at the given location. Furthermore, this allows for the Entity to be customized further prior to traditional "ticking" and processing by core systems.

      Parameters:
      type - The type
      Returns:
      An entity, if one was created
      Throws:
      IllegalArgumentException - If the position or entity type is not valid to create
      IllegalStateException - If a constructor cannot be found
      See Also:
    • spawnEntity

      boolean spawnEntity(Entity entity)
      Spawns an Entity using the already set properties (world, position, rotation) and applicable Values with the specified Cause for spawning the entity.

      Note that for the Cause to be useful in the expected SpawnEntityEvent, a SpawnType should be provided in the EventContext for other plugins to understand and have finer control over the event.

      The requirements involve that all necessary setup of states and data is already preformed on the entity retrieved from the various EntityVolume.Modifiable.createEntity(EntityType,Vector3d) methods. Calling this will make the now-spawned entity able to be processed by various systems.

      If the entity was unable to spawn, the entity is not removed, but it should be taken note that there can be many reasons for a failure.

      Parameters:
      entity - The entity to spawn
      Returns:
      True if successful, false if not
      See Also:
    • spawnEntities

      Collection<Entity> spawnEntities(Iterable<? extends Entity> entities)
      Similar to spawnEntity(Entity) except where multiple entities can be attempted to be spawned with a customary Cause. The recommended use is to easily process the entity spawns without interference with the cause tracking system.
      Parameters:
      entities - The entities which spawned correctly, or empty if none
      Returns:
      True if any of the entities were successfully spawned
      See Also:
    • asHighestLocation

      ServerLocation asHighestLocation()
      Gets the highest ServerLocation at this location.
      Returns:
      The highest location at this location
      See Also:
    • createSnapshot

      BlockSnapshot createSnapshot()
      Gets a snapshot of this block at the current point in time.

      A snapshot is disconnected from the World that it was taken from so changes to the original block do not affect the snapshot.

      Returns:
      A snapshot
    • scheduledBlockUpdates

      Collection<? extends ScheduledUpdate<BlockType>> scheduledBlockUpdates()
      Gets a list of ScheduledUpdates for the block at this location.
      Returns:
      A list of scheduled block updates on this location
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(int delay, TemporalUnit temporalUnit)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      temporalUnit - The temporal unit of the delay
      Returns:
      The newly created scheduled update
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay, TaskPriority priority)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay, in Ticks, before the scheduled update should be processed
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
      Throws:
      IllegalArgumentException - if the delay is infinite
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(int delay, TemporalUnit temporalUnit, TaskPriority priority)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      temporalUnit - The temporal unit of the delay
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay, in Ticks, before the scheduled update should be processed
      Returns:
      The newly created scheduled update
      Throws:
      IllegalArgumentException - if the delay is infinite
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(Duration delay)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      Returns:
      The newly created scheduled update
    • scheduleBlockUpdate

      ScheduledUpdate<BlockType> scheduleBlockUpdate(Duration delay, TaskPriority priority)
      Adds a new ScheduledUpdate for the block at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
    • scheduledFluidUpdates

      Collection<? extends ScheduledUpdate<FluidType>> scheduledFluidUpdates()
      Gets a list of ScheduledUpdates for the fluid at this location.
      Returns:
      A list of scheduled fluid updates on this location
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(int delay, TemporalUnit temporalUnit)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      temporalUnit - The temporal unit of the delay
      Returns:
      The newly created scheduled update
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(int delay, TemporalUnit temporalUnit, TaskPriority priority)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      temporalUnit - The temporal unit of the delay
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      ticks - The delay, in Ticks, before the scheduled update should be processed
      Returns:
      The newly created scheduled update
      Throws:
      IllegalArgumentException - if the delay is infinite
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks, TaskPriority priority)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      ticks - The delay, in Ticks, before the scheduled update should be processed
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
      Throws:
      IllegalArgumentException - if the delay is infinite
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(Duration delay)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      Returns:
      The newly created scheduled update
    • scheduleFluidUpdate

      ScheduledUpdate<FluidType> scheduleFluidUpdate(Duration delay, TaskPriority priority)
      Adds a new ScheduledUpdate for the fluid at this location.
      Parameters:
      delay - The delay before the scheduled update should be processed
      priority - The priority of the scheduled update
      Returns:
      The newly created scheduled update
    • withWorld

      ServerLocation withWorld(ServerWorld world)
      Description copied from interface: Location
      Create a new instance with a new World.
      Specified by:
      withWorld in interface Location<ServerWorld,ServerLocation>
      Parameters:
      world - The new world
      Returns:
      A new instance
    • withPosition

      ServerLocation withPosition(Vector3d position)
      Description copied from interface: Location
      Create a new instance with a new position.
      Specified by:
      withPosition in interface Location<ServerWorld,ServerLocation>
      Parameters:
      position - The new position
      Returns:
      A new instance
    • withBlockPosition

      ServerLocation withBlockPosition(Vector3i position)
      Description copied from interface: Location
      Create a new instance with a new block position.
      Specified by:
      withBlockPosition in interface Location<ServerWorld,ServerLocation>
      Parameters:
      position - The new position
      Returns:
      A new instance
    • sub

      Description copied from interface: Location
      Subtract another Vector3d to the position on this instance, returning a new Location instance.
      Specified by:
      sub in interface Location<ServerWorld,ServerLocation>
      Parameters:
      v - The vector to subtract
      Returns:
      A new instance
    • sub

      Description copied from interface: Location
      Subtract another Vector3i to the position on this instance, returning a new Location instance.
      Specified by:
      sub in interface Location<ServerWorld,ServerLocation>
      Parameters:
      v - The vector to subtract
      Returns:
      A new instance
    • sub

      ServerLocation sub(double x, double y, double z)
      Description copied from interface: Location
      Subtract vector components to the position on this instance, returning a new Location instance.
      Specified by:
      sub in interface Location<ServerWorld,ServerLocation>
      Parameters:
      x - The x component
      y - The y component
      z - The z component
      Returns:
      A new instance
    • add

      Description copied from interface: Location
      Add another Vector3d to the position on this instance, returning a new Location instance.
      Specified by:
      add in interface Location<ServerWorld,ServerLocation>
      Parameters:
      v - The vector to add
      Returns:
      A new instance
    • add

      Description copied from interface: Location
      Add another Vector3i to the position on this instance, returning a new Location instance.
      Specified by:
      add in interface Location<ServerWorld,ServerLocation>
      Parameters:
      v - The vector to add
      Returns:
      A new instance
    • add

      ServerLocation add(double x, double y, double z)
      Description copied from interface: Location
      Add vector components to the position on this instance, returning a new Location instance.
      Specified by:
      add in interface Location<ServerWorld,ServerLocation>
      Parameters:
      x - The x component
      y - The y component
      z - The z component
      Returns:
      A new instance
    • relativeTo

      ServerLocation relativeTo(Direction direction)
      Description copied from interface: Location
      Gets the location next to this one in the given direction. Always moves by a unit amount, even diagonally.
      Specified by:
      relativeTo in interface Location<ServerWorld,ServerLocation>
      Parameters:
      direction - The direction to move in
      Returns:
      The location in that direction
    • relativeToBlock

      ServerLocation relativeToBlock(Direction direction)
      Description copied from interface: Location
      Gets the location next to this one in the given direction. Always moves by a block amount, even diagonally.

      Direction.Division.SECONDARY_ORDINAL directions are not a valid argument. These will throw an exception.

      Specified by:
      relativeToBlock in interface Location<ServerWorld,ServerLocation>
      Parameters:
      direction - The direction to move in
      Returns:
      The location in that direction