Package org.spongepowered.api.world
Interface Location<W extends World<W,L>,L extends Location<W,L>>
-
- All Known Subinterfaces:
ClientLocation
,ServerLocation
public interface Location<W extends World<W,L>,L extends Location<W,L>>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description L
add(double x, double y, double z)
Add vector components to the position on this instance, returning a new Location instance.L
add(Vector3d v)
Add another Vector3d to the position on this instance, returning a new Location instance.L
add(Vector3i v)
Add another Vector3i to the position on this instance, returning a new Location instance.Biome
biome()
Gets the block at this location.Vector3i
biomePosition()
Gets the underlying biome position.BlockState
block()
Gets theBlockState
for this location.java.util.Optional<? extends BlockEntity>
blockEntity()
Gets the associatedBlockEntity
on this block.Vector3i
blockPosition()
Gets the underlying block position.default BlockType
blockType()
Gets theBlockType
for this location.int
blockX()
Gets the floored X component of this instance's position.int
blockY()
Gets the floored Y component of this instance's position.int
blockZ()
Gets the floored Z component of this instance's position.Vector3i
chunkPosition()
Gets the underlying chunk position.FluidState
fluid()
Gets theFluidState
for this location.boolean
hasBlock()
Returns true if this location has a block at itsblockPosition()
.boolean
hasBlockEntity()
Checks for whether the block at this location contains block entity data.boolean
inWorld(W world)
Returns true if this location is in the given world.boolean
isAvailable()
Gets whether this location is available.boolean
isValid()
Gets whether this location is valid.default java.util.Optional<ServerLocation>
onServer()
Vector3d
position()
Gets the underlying position.L
relativeTo(Direction direction)
Gets the location next to this one in the given direction.L
relativeToBlock(Direction direction)
Gets the location next to this one in the given direction.boolean
setBlock(BlockState state)
Replace the block at this location with a new state.boolean
setBlock(BlockState state, BlockChangeFlag flag)
Replace the block at this location with a new state.boolean
setBlockType(BlockType type)
Replace the block type at this location by a new type.boolean
setBlockType(BlockType type, BlockChangeFlag flag)
Replace the block type at this location by a new type.L
sub(double x, double y, double z)
Subtract vector components to the position on this instance, returning a new Location instance.L
sub(Vector3d v)
Subtract another Vector3d to the position on this instance, returning a new Location instance.L
sub(Vector3i v)
Subtract another Vector3i to the position on this instance, returning a new Location instance.L
withBlockPosition(Vector3i position)
Create a new instance with a new block position.L
withPosition(Vector3d position)
Create a new instance with a new position.L
withWorld(W world)
Create a new instance with a new World.W
world()
Gets the underlying world.java.util.Optional<W>
worldIfAvailable()
Gets the underlyingWorld
if it's available.double
x()
Gets the X component of this instance's position.double
y()
Gets the Y component of this instance's position.double
z()
Gets the Z component of this instance's position.
-
-
-
Method Detail
-
world
W world()
Gets the underlying world. Throws aIllegalStateException
if the world isn't available.- Returns:
- The underlying world
- See Also:
worldIfAvailable()
-
worldIfAvailable
java.util.Optional<W> worldIfAvailable()
- Returns:
- The underlying world, if available
- See Also:
isAvailable()
-
isAvailable
boolean isAvailable()
Gets whether this location is available. A location is available when the targetWorld
exists and is loaded.- Returns:
- Whether the location is available
-
isValid
boolean isValid()
Gets whether this location is valid. A location is valid when the targetWorld
exists, this can be loaded or unloaded.- Returns:
- Whether the location is valid
-
position
Vector3d position()
Gets the underlying position.- Returns:
- The underlying position
-
blockPosition
Vector3i blockPosition()
Gets the underlying block position.- Returns:
- The underlying block position
-
chunkPosition
Vector3i chunkPosition()
Gets the underlying chunk position.- Returns:
- The underlying chunk position
-
biomePosition
Vector3i biomePosition()
Gets the underlying biome position.- Returns:
- The underlying biome position
-
x
double x()
Gets the X component of this instance's position.- Returns:
- The x component
-
y
double y()
Gets the Y component of this instance's position.- Returns:
- The y component
-
z
double z()
Gets the Z component of this instance's position.- Returns:
- The z component
-
blockX
int blockX()
Gets the floored X component of this instance's position.- Returns:
- The floored x component
-
blockY
int blockY()
Gets the floored Y component of this instance's position.- Returns:
- The floored y component
-
blockZ
int blockZ()
Gets the floored Z component of this instance's position.- Returns:
- The floored z component
-
onServer
default java.util.Optional<ServerLocation> onServer()
-
inWorld
boolean inWorld(W world)
Returns true if this location is in the given world. This is implemented as anObject.equals(Object)
check.- Parameters:
world
- The world to check- Returns:
- Whether this location is in the world
-
withWorld
L withWorld(W world)
Create a new instance with a new World.- Parameters:
world
- The new world- Returns:
- A new instance
-
withPosition
L withPosition(Vector3d position)
Create a new instance with a new position.- Parameters:
position
- The new position- Returns:
- A new instance
-
withBlockPosition
L withBlockPosition(Vector3i position)
Create a new instance with a new block position.- Parameters:
position
- The new position- Returns:
- A new instance
-
sub
L sub(Vector3d v)
Subtract another Vector3d to the position on this instance, returning a new Location instance.- Parameters:
v
- The vector to subtract- Returns:
- A new instance
-
sub
L sub(Vector3i v)
Subtract another Vector3i to the position on this instance, returning a new Location instance.- Parameters:
v
- The vector to subtract- Returns:
- A new instance
-
sub
L sub(double x, double y, double z)
Subtract vector components to the position on this instance, returning a new Location instance.- Parameters:
x
- The x componenty
- The y componentz
- The z component- Returns:
- A new instance
-
add
L add(Vector3d v)
Add another Vector3d to the position on this instance, returning a new Location instance.- Parameters:
v
- The vector to add- Returns:
- A new instance
-
add
L add(Vector3i v)
Add another Vector3i to the position on this instance, returning a new Location instance.- Parameters:
v
- The vector to add- Returns:
- A new instance
-
add
L add(double x, double y, double z)
Add vector components to the position on this instance, returning a new Location instance.- Parameters:
x
- The x componenty
- The y componentz
- The z component- Returns:
- A new instance
-
relativeTo
L relativeTo(Direction direction)
Gets the location next to this one in the given direction. Always moves by a unit amount, even diagonally.- Parameters:
direction
- The direction to move in- Returns:
- The location in that direction
-
relativeToBlock
L relativeToBlock(Direction direction)
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.- Parameters:
direction
- The direction to move in- Returns:
- The location in that direction
- Throws:
java.lang.IllegalArgumentException
- If the direction is aDirection.Division.SECONDARY_ORDINAL
-
biome
Biome biome()
Gets the block at this location.- Returns:
- The biome at this location
-
hasBlock
boolean hasBlock()
Returns true if this location has a block at itsblockPosition()
.- Returns:
- Whether or not there is a block at this location.
-
block
BlockState block()
Gets theBlockState
for this location.- Returns:
- The block state
-
blockType
default BlockType blockType()
Gets theBlockType
for this location.- Returns:
- The block type
-
fluid
FluidState fluid()
Gets theFluidState
for this location.- Returns:
- The fluid state
-
hasBlockEntity
boolean hasBlockEntity()
Checks for whether the block at this location contains block entity data.- Returns:
- True if the block at this location has block entity data, false otherwise
-
blockEntity
java.util.Optional<? extends BlockEntity> blockEntity()
Gets the associatedBlockEntity
on this block.- Returns:
- The associated block entity, if available
-
setBlock
boolean setBlock(BlockState state)
Replace the block at this location with a new state.This will remove any extended block data at the given position.
- Parameters:
state
- The new block state- Returns:
- True if the block change was successful
-
setBlock
boolean setBlock(BlockState state, BlockChangeFlag flag)
Replace the block at this location with a new state.This will remove any extended block data at the given position.
- Parameters:
state
- The new block stateflag
- The various change flags controlling some interactions- Returns:
- True if the block change was successful
-
setBlockType
boolean setBlockType(BlockType type)
Replace the block type at this location by a new type.This will remove any extended block data at the given position.
- Parameters:
type
- The new type- Returns:
- True if the block change was successful
-
setBlockType
boolean setBlockType(BlockType type, BlockChangeFlag flag)
Replace the block type at this location by a new type.This will remove any extended block data at the given position.
- Parameters:
type
- The new typeflag
- The various change flags controlling some interactions- Returns:
- True if the block change was successful
-
-