Interface ServerLocation
-
- All Superinterfaces:
DataHolder
,DataHolder.Mutable
,DataSerializable
,DirectionRelativeDataHolder
,DirectionRelativeDataHolder.Mutable
,Location<ServerWorld,ServerLocation>
,ValueContainer
public interface ServerLocation extends DataHolder.Mutable, DirectionRelativeDataHolder.Mutable, Location<ServerWorld,ServerLocation>, DataSerializable
A position within a particularServerWorld
.Locations are immutable. Methods that change the properties of the location create a new instance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ServerLocation.Factory
-
Nested classes/interfaces inherited from interface org.spongepowered.api.data.DataHolder
DataHolder.Immutable<I extends DataHolder.Immutable<I>>, DataHolder.Mutable
-
Nested classes/interfaces inherited from interface org.spongepowered.api.data.DirectionRelativeDataHolder
DirectionRelativeDataHolder.Immutable<I extends DirectionRelativeDataHolder.Immutable<I>>, DirectionRelativeDataHolder.Mutable
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description ServerLocation
add(double x, double y, double z)
Add vector components to the position on this instance, returning a new Location instance.ServerLocation
add(Vector3d v)
Add another Vector3d to the position on this instance, returning a new Location instance.ServerLocation
add(Vector3i v)
Add another Vector3i to the position on this instance, returning a new Location instance.ServerLocation
asHighestLocation()
Gets the highestServerLocation
at this location.LocatableBlock
asLocatableBlock()
Gets aLocatableBlock
.<E extends Entity>
EcreateEntity(EntityType<E> type)
Create an entity instance at the given position.BlockSnapshot
createSnapshot()
Gets a snapshot of this block at the current point in time.<T> T
map(java.util.function.BiFunction<ServerWorld,Vector3d,T> mapper)
Calls the mapper function on the world and position.<T> T
mapBiome(java.util.function.BiFunction<ServerWorld,Vector3i,T> mapper)
Calls the mapper function on the world and biome position.<T> T
mapBlock(java.util.function.BiFunction<ServerWorld,Vector3i,T> mapper)
Calls the mapper function on the world and block position.<T> T
mapChunk(java.util.function.BiFunction<ServerWorld,Vector3i,T> mapper)
Calls the mapper function on the world and chunk position.static ServerLocation
of(ResourceKey worldKey, double x, double y, double z)
static ServerLocation
of(ResourceKey worldKey, int x, int y, int z)
static ServerLocation
of(ResourceKey worldKey, Vector3d position)
static ServerLocation
of(ResourceKey worldKey, Vector3i position)
static ServerLocation
of(ServerWorld world, double x, double y, double z)
static ServerLocation
of(ServerWorld world, int x, int y, int z)
static ServerLocation
of(ServerWorld world, Vector3d position)
static ServerLocation
of(ServerWorld world, Vector3i position)
ServerLocation
relativeTo(Direction direction)
Gets the location next to this one in the given direction.ServerLocation
relativeToBlock(Direction direction)
Gets the location next to this one in the given direction.boolean
removeBlock()
Remove the block at this position by replacing it withBlockTypes.AIR
.boolean
restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag)
Replace the block at this position with a copy of the given snapshot.ScheduledUpdate<BlockType>
scheduleBlockUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit)
Adds a newScheduledUpdate
for the block at this location.ScheduledUpdate<BlockType>
scheduleBlockUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.ScheduledUpdate<BlockType>
scheduleBlockUpdate(java.time.Duration delay)
Adds a newScheduledUpdate
for the block at this location.ScheduledUpdate<BlockType>
scheduleBlockUpdate(java.time.Duration delay, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.ScheduledUpdate<BlockType>
scheduleBlockUpdate(Ticks delay)
Adds a newScheduledUpdate
for the block at this location.ScheduledUpdate<BlockType>
scheduleBlockUpdate(Ticks delay, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.java.util.Collection<? extends ScheduledUpdate<BlockType>>
scheduledBlockUpdates()
Gets a list ofScheduledUpdate
s for the block at this location.java.util.Collection<? extends ScheduledUpdate<FluidType>>
scheduledFluidUpdates()
Gets a list ofScheduledUpdate
s for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit)
Adds a newScheduledUpdate
for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(java.time.Duration delay)
Adds a newScheduledUpdate
for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(java.time.Duration delay, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(Ticks ticks)
Adds a newScheduledUpdate
for the fluid at this location.ScheduledUpdate<FluidType>
scheduleFluidUpdate(Ticks ticks, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.java.util.Collection<Entity>
spawnEntities(java.lang.Iterable<? extends Entity> entities)
Similar tospawnEntity(Entity)
except where multiple entities can be attempted to be spawned with a customaryCause
.boolean
spawnEntity(Entity entity)
ServerLocation
sub(double x, double y, double z)
Subtract vector components to the position on this instance, returning a new Location instance.ServerLocation
sub(Vector3d v)
Subtract another Vector3d to the position on this instance, returning a new Location instance.ServerLocation
sub(Vector3i v)
Subtract another Vector3i to the position on this instance, returning a new Location instance.ServerLocation
withBlockPosition(Vector3i position)
Create a new instance with a new block position.ServerLocation
withPosition(Vector3d position)
Create a new instance with a new position.ServerLocation
withWorld(ServerWorld world)
Create a new instance with a new World.ResourceKey
worldKey()
Gets theUUID
of the world.-
Methods inherited from interface org.spongepowered.api.data.DataHolder.Mutable
copyFrom, copyFrom, offer, offer, offer, offer, offerAll, offerAll, offerAll, offerAll, offerAll, offerAll, offerSingle, offerSingle, offerSingle, offerSingle, remove, remove, remove, removeAll, removeAll, removeAll, removeAll, removeAll, removeAll, removeKey, removeKey, removeSingle, removeSingle, transform, transform, tryOffer, tryOffer, tryOffer, undo
-
Methods inherited from interface org.spongepowered.api.data.persistence.DataSerializable
contentVersion, toContainer
-
Methods inherited from interface org.spongepowered.api.data.DirectionRelativeDataHolder
get, getDouble, getInt, getLong
-
Methods inherited from interface org.spongepowered.api.world.Location
biome, biomePosition, block, blockEntity, blockPosition, blockType, blockX, blockY, blockZ, chunkPosition, fluid, hasBlock, hasBlockEntity, inWorld, isAvailable, isValid, onServer, position, setBlock, setBlock, setBlockType, setBlockType, world, worldIfAvailable, x, y, z
-
-
-
-
Method Detail
-
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 theUUID
of the world.- Returns:
- The world unique id
-
asLocatableBlock
LocatableBlock asLocatableBlock()
Gets aLocatableBlock
.- Returns:
- The locatable block of this location.
-
map
<T> T map(java.util.function.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(java.util.function.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(java.util.function.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(java.util.function.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 snapshotforce
- If true, forces block state to be set even if theBlockType
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 withBlockTypes.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 theEntity
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:
java.lang.IllegalArgumentException
- If the position or entity type is not valid to createjava.lang.IllegalStateException
- If a constructor cannot be found- See Also:
EntityVolume.Modifiable.createEntity(EntityType, Vector3d)
-
spawnEntity
boolean spawnEntity(Entity entity)
Spawns anEntity
using the already set properties (world, position, rotation) and applicableValue
s with the specifiedCause
for spawning the entity.Note that for the
Cause
to be useful in the expectedSpawnEntityEvent
, aSpawnType
should be provided in theEventContext
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:
EntityVolume.Modifiable.spawnEntity(Entity)
-
spawnEntities
java.util.Collection<Entity> spawnEntities(java.lang.Iterable<? extends Entity> entities)
Similar tospawnEntity(Entity)
except where multiple entities can be attempted to be spawned with a customaryCause
. 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:
EntityVolume.Modifiable.spawnEntities(Iterable)
-
asHighestLocation
ServerLocation asHighestLocation()
Gets the highestServerLocation
at this location.- Returns:
- The highest location at this location
- See Also:
BlockVolume.highestPositionAt(Vector3i)
-
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
java.util.Collection<? extends ScheduledUpdate<BlockType>> scheduledBlockUpdates()
Gets a list ofScheduledUpdate
s for the block at this location.- Returns:
- A list of scheduled block updates on this location
-
scheduleBlockUpdate
ScheduledUpdate<BlockType> scheduleBlockUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit)
Adds a newScheduledUpdate
for the block at this location.- Parameters:
delay
- The delay before the scheduled update should be processedtemporalUnit
- The temporal unit of the delay- Returns:
- The newly created scheduled update
-
scheduleBlockUpdate
ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.- Parameters:
delay
- The delay, inTicks
, before the scheduled update should be processedpriority
- The priority of the scheduled update- Returns:
- The newly created scheduled update
-
scheduleBlockUpdate
ScheduledUpdate<BlockType> scheduleBlockUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.- Parameters:
delay
- The delay before the scheduled update should be processedtemporalUnit
- The temporal unit of the delaypriority
- The priority of the scheduled update- Returns:
- The newly created scheduled update
-
scheduleBlockUpdate
ScheduledUpdate<BlockType> scheduleBlockUpdate(Ticks delay)
Adds a newScheduledUpdate
for the block at this location.- Parameters:
delay
- The delay, inTicks
, before the scheduled update should be processed- Returns:
- The newly created scheduled update
-
scheduleBlockUpdate
ScheduledUpdate<BlockType> scheduleBlockUpdate(java.time.Duration delay)
Adds a newScheduledUpdate
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(java.time.Duration delay, TaskPriority priority)
Adds a newScheduledUpdate
for the block at this location.- Parameters:
delay
- The delay before the scheduled update should be processedpriority
- The priority of the scheduled update- Returns:
- The newly created scheduled update
-
scheduledFluidUpdates
java.util.Collection<? extends ScheduledUpdate<FluidType>> scheduledFluidUpdates()
Gets a list ofScheduledUpdate
s for the fluid at this location.- Returns:
- A list of scheduled fluid updates on this location
-
scheduleFluidUpdate
ScheduledUpdate<FluidType> scheduleFluidUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit)
Adds a newScheduledUpdate
for the fluid at this location.- Parameters:
delay
- The delay before the scheduled update should be processedtemporalUnit
- The temporal unit of the delay- Returns:
- The newly created scheduled update
-
scheduleFluidUpdate
ScheduledUpdate<FluidType> scheduleFluidUpdate(int delay, java.time.temporal.TemporalUnit temporalUnit, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.- Parameters:
delay
- The delay before the scheduled update should be processedtemporalUnit
- The temporal unit of the delaypriority
- The priority of the scheduled update- Returns:
- The newly created scheduled update
-
scheduleFluidUpdate
ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks)
Adds a newScheduledUpdate
for the fluid at this location.- Parameters:
ticks
- The delay, inTicks
, before the scheduled update should be processed- Returns:
- The newly created scheduled update
-
scheduleFluidUpdate
ScheduledUpdate<FluidType> scheduleFluidUpdate(Ticks ticks, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.- Parameters:
ticks
- The delay, inTicks
, before the scheduled update should be processedpriority
- The priority of the scheduled update- Returns:
- The newly created scheduled update
-
scheduleFluidUpdate
ScheduledUpdate<FluidType> scheduleFluidUpdate(java.time.Duration delay)
Adds a newScheduledUpdate
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(java.time.Duration delay, TaskPriority priority)
Adds a newScheduledUpdate
for the fluid at this location.- Parameters:
delay
- The delay before the scheduled update should be processedpriority
- 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 interfaceLocation<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 interfaceLocation<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 interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
position
- The new position- Returns:
- A new instance
-
sub
ServerLocation sub(Vector3d v)
Description copied from interface:Location
Subtract another Vector3d to the position on this instance, returning a new Location instance.- Specified by:
sub
in interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
v
- The vector to subtract- Returns:
- A new instance
-
sub
ServerLocation sub(Vector3i v)
Description copied from interface:Location
Subtract another Vector3i to the position on this instance, returning a new Location instance.- Specified by:
sub
in interfaceLocation<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 interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
x
- The x componenty
- The y componentz
- The z component- Returns:
- A new instance
-
add
ServerLocation add(Vector3d v)
Description copied from interface:Location
Add another Vector3d to the position on this instance, returning a new Location instance.- Specified by:
add
in interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
v
- The vector to add- Returns:
- A new instance
-
add
ServerLocation add(Vector3i v)
Description copied from interface:Location
Add another Vector3i to the position on this instance, returning a new Location instance.- Specified by:
add
in interfaceLocation<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 interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
x
- The x componenty
- The y componentz
- 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 interfaceLocation<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 interfaceLocation<ServerWorld,ServerLocation>
- Parameters:
direction
- The direction to move in- Returns:
- The location in that direction
-
-