Metadatable
public interface Block extends Metadatable
Modifier and Type | Method | Description |
---|---|---|
boolean |
breakNaturally() |
Breaks the block and spawns items as if a player had digged it regardless
of the tool.
|
boolean |
breakNaturally(@NotNull ItemStack tool,
boolean triggerEffect) |
Breaks the block and spawns items as if a player had digged it with a
specific tool
|
boolean |
breakNaturally(@Nullable ItemStack tool) |
Breaks the block and spawns items as if a player had digged it with a
specific tool
|
@NotNull Biome |
getBiome() |
Returns the biome that this block resides in
|
@NotNull BlockData |
getBlockData() |
Gets the complete block data for this block
|
default long |
getBlockKey() |
Returns this block's coordinates packed into a long value.
|
static long |
getBlockKey(int x,
int y,
int z) |
Returns the specified block coordinates packed into a long value
|
static int |
getBlockKeyX(long packed) |
Returns the x component from the packed value.
|
static int |
getBlockKeyY(long packed) |
Returns the y component from the packed value.
|
static int |
getBlockKeyZ(long packed) |
Returns the z component from the packed value.
|
int |
getBlockPower() |
Returns the redstone power being provided to this block
|
int |
getBlockPower(@NotNull BlockFace face) |
Returns the redstone power being provided to this block face
|
@NotNull BoundingBox |
getBoundingBox() |
Gets the approximate bounding box for this block.
|
@NotNull Chunk |
getChunk() |
Gets the chunk which contains this block
|
byte |
getData() |
Deprecated.
Magic value
|
@NotNull Collection<ItemStack> |
getDrops() |
Returns a list of items which would drop by destroying this block
|
@NotNull Collection<ItemStack> |
getDrops(@NotNull ItemStack tool,
@Nullable Entity entity) |
Returns a list of items which would drop by the entity destroying this
block with a specific tool
|
@NotNull Collection<ItemStack> |
getDrops(@Nullable ItemStack tool) |
Returns a list of items which would drop by destroying this block with
a specific tool
|
@Nullable BlockFace |
getFace(@NotNull Block block) |
Gets the face relation of this block compared to the given block.
|
double |
getHumidity() |
Gets the humidity of the biome of this block
|
byte |
getLightFromBlocks() |
Get the amount of light at this block from nearby blocks.
|
byte |
getLightFromSky() |
Get the amount of light at this block from the sky.
|
byte |
getLightLevel() |
Gets the light level between 0-15
|
@NotNull Location |
getLocation() |
Gets the Location of the block
|
@Nullable Location |
getLocation(@Nullable Location loc) |
Stores the location of the block in the provided Location object.
|
@NotNull PistonMoveReaction |
getPistonMoveReaction() |
Returns the reaction of the block when moved by a piston
|
@NotNull Block |
getRelative(int modX,
int modY,
int modZ) |
Gets the block at the given offsets
|
@NotNull Block |
getRelative(@NotNull BlockFace face) |
Gets the block at the given face
|
@NotNull Block |
getRelative(@NotNull BlockFace face,
int distance) |
Gets the block at the given distance of the given face
|
BlockSoundGroup |
getSoundGroup() |
Gets the
BlockSoundGroup for this block. |
@NotNull BlockState |
getState() |
Captures the current state of this block.
|
@NotNull BlockState |
getState(boolean useSnapshot) |
|
double |
getTemperature() |
Gets the temperature of this block.
|
@NotNull Material |
getType() |
Gets the type of this block
|
@NotNull World |
getWorld() |
Gets the world which contains this Block
|
int |
getX() |
Gets the x-coordinate of this block
|
int |
getY() |
Gets the y-coordinate of this block
|
int |
getZ() |
Gets the z-coordinate of this block
|
boolean |
isBlockFaceIndirectlyPowered(@NotNull BlockFace face) |
Returns true if the block face is being indirectly powered by Redstone.
|
boolean |
isBlockFacePowered(@NotNull BlockFace face) |
Returns true if the block face is being powered by Redstone.
|
boolean |
isBlockIndirectlyPowered() |
Returns true if the block is being indirectly powered by Redstone.
|
boolean |
isBlockPowered() |
Returns true if the block is being powered by Redstone.
|
boolean |
isEmpty() |
Checks if this block is empty.
|
boolean |
isLiquid() |
Checks if this block is liquid.
|
boolean |
isPassable() |
Checks if this block is passable.
|
@Nullable RayTraceResult |
rayTrace(@NotNull Location start,
@NotNull Vector direction,
double maxDistance,
@NotNull FluidCollisionMode fluidCollisionMode) |
Performs a ray trace that checks for collision with this specific block
in its current state using its precise collision shape.
|
void |
setBiome(@NotNull Biome bio) |
Sets the biome that this block resides in
|
void |
setBlockData(@NotNull BlockData data) |
Sets the complete data for this block
|
void |
setBlockData(@NotNull BlockData data,
boolean applyPhysics) |
Sets the complete data for this block
Note that applyPhysics = false is not in general safe. |
void |
setType(@NotNull Material type) |
Sets the type of this block
|
void |
setType(@NotNull Material type,
boolean applyPhysics) |
Sets the type of this block
Note that applyPhysics = false is not in general safe. |
getMetadata, hasMetadata, removeMetadata, setMetadata
@Deprecated byte getData()
@NotNull @NotNull BlockData getBlockData()
@NotNull @NotNull Block getRelative(int modX, int modY, int modZ)
modX
- X-coordinate offsetmodY
- Y-coordinate offsetmodZ
- Z-coordinate offset@NotNull @NotNull Block getRelative(@NotNull @NotNull BlockFace face)
This method is equal to getRelative(face, 1)
face
- Face of this block to returngetRelative(BlockFace, int)
@NotNull @NotNull Block getRelative(@NotNull @NotNull BlockFace face, int distance)
For example, the following method places water at 100,102,100; two blocks above 100,100,100.
Block block = world.getBlockAt(100, 100, 100); Block shower = block.getRelative(BlockFace.UP, 2); shower.setType(Material.WATER);
face
- Face of this block to returndistance
- Distance to get the block at@NotNull @NotNull Material getType()
byte getLightLevel()
byte getLightFromSky()
Any light given from other sources (such as blocks like torches) will be ignored.
byte getLightFromBlocks()
Any light given from other sources (such as the sun) will be ignored.
@NotNull @NotNull World getWorld()
int getX()
int getY()
int getZ()
default long getBlockKey()
Block.getBlockKey(this.getX(), this.getY(), this.getZ())
getBlockKey(int, int, int)
static long getBlockKey(int x, int y, int z)
The return value can be computed as follows:
long value = ((long)x & 0x7FFFFFF) | (((long)z & 0x7FFFFFF) << 27) | ((long)y << 54);
And may be unpacked as follows:
int x = (int) ((packed << 37) >> 37);
int y = (int) (packed >>> 54);
int z = (int) ((packed << 10) >> 37);
static int getBlockKeyX(long packed)
packed
- The packed value, as computed by getBlockKey(int, int, int)
getBlockKey(int, int, int)
static int getBlockKeyY(long packed)
packed
- The packed value, as computed by getBlockKey(int, int, int)
getBlockKey(int, int, int)
static int getBlockKeyZ(long packed)
packed
- The packed value, as computed by getBlockKey(int, int, int)
getBlockKey(int, int, int)
@NotNull @NotNull Location getLocation()
@Contract("null -> null; !null -> !null") @Nullable @Nullable Location getLocation(@Nullable @Nullable Location loc)
If the provided Location is null this method does nothing and returns null.
loc
- the location to copy into@NotNull @NotNull Chunk getChunk()
void setBlockData(@NotNull @NotNull BlockData data)
data
- new block specific datavoid setBlockData(@NotNull @NotNull BlockData data, boolean applyPhysics)
Bisected
block. If you are
using a custom populator, then this parameter may also be required to
prevent triggering infinite chunk loads on border blocks. This method
should NOT be used to "hack" physics by placing blocks in impossible
locations. Such blocks are liable to be removed on various events such as
world upgrades. Furthermore setting large amounts of such blocks in close
proximity may overload the server physics engine if an update is
triggered at a later point. If this occurs, the resulting behavior is
undefined.data
- new block specific dataapplyPhysics
- false to cancel physics from the changed blockvoid setType(@NotNull @NotNull Material type)
type
- Material to change this block tovoid setType(@NotNull @NotNull Material type, boolean applyPhysics)
Bisected
block. If you are
using a custom populator, then this parameter may also be required to
prevent triggering infinite chunk loads on border blocks. This method
should NOT be used to "hack" physics by placing blocks in impossible
locations. Such blocks are liable to be removed on various events such as
world upgrades. Furthermore setting large amounts of such blocks in close
proximity may overload the server physics engine if an update is
triggered at a later point. If this occurs, the resulting behavior is
undefined.type
- Material to change this block toapplyPhysics
- False to cancel physics on the changed block.@Nullable @Nullable BlockFace getFace(@NotNull @NotNull Block block)
For example:
Block current = world.getBlockAt(100, 100, 100);
Block target = world.getBlockAt(100, 101, 100);
current.getFace(target) == BlockFace.Up;
block
- Block to compare against this block@NotNull @NotNull BlockState getState()
The returned object will never be updated, and you are not guaranteed that (for example) a sign is still a sign after you capture its state.
@NotNull @NotNull BlockState getState(boolean useSnapshot)
useSnapshot
- if this block is a TE, should we create a fully copy of the TileEntityoptionally disables use of snapshot, to operate on real block data
@NotNull @NotNull Biome getBiome()
void setBiome(@NotNull @NotNull Biome bio)
bio
- new Biome type for this blockboolean isBlockPowered()
boolean isBlockIndirectlyPowered()
boolean isBlockFacePowered(@NotNull @NotNull BlockFace face)
face
- The block faceboolean isBlockFaceIndirectlyPowered(@NotNull @NotNull BlockFace face)
face
- The block faceint getBlockPower(@NotNull @NotNull BlockFace face)
face
- the face of the block to query or BlockFace.SELF for the
block itselfint getBlockPower()
boolean isEmpty()
A block is considered empty when getType()
returns Material.AIR
.
boolean isLiquid()
A block is considered liquid when getType()
returns Material.WATER
or Material.LAVA
.
double getTemperature()
If the raw biome temperature without adjusting for height effects is
required then please use World.getTemperature(int, int)
.
double getHumidity()
@NotNull @NotNull PistonMoveReaction getPistonMoveReaction()
boolean breakNaturally()
boolean breakNaturally(@Nullable @Nullable ItemStack tool)
tool
- The tool or item in hand used for diggingboolean breakNaturally(@NotNull @NotNull ItemStack tool, boolean triggerEffect)
tool
- The tool or item in hand used for diggingtriggerEffect
- Play the block break particle effect and sound@NotNull @NotNull Collection<ItemStack> getDrops()
@NotNull @NotNull Collection<ItemStack> getDrops(@Nullable @Nullable ItemStack tool)
tool
- The tool or item in hand used for digging@NotNull @NotNull Collection<ItemStack> getDrops(@NotNull @NotNull ItemStack tool, @Nullable @Nullable Entity entity)
tool
- The tool or item in hand used for diggingentity
- the entity destroying the blockboolean isPassable()
A block is passable if it has no colliding parts that would prevent players from moving through it.
Examples: Tall grass, flowers, signs, etc. are passable, but open doors, fence gates, trap doors, etc. are not because they still have parts that can be collided with.
true
if passable@Nullable @Nullable RayTraceResult rayTrace(@NotNull @NotNull Location start, @NotNull @NotNull Vector direction, double maxDistance, @NotNull @NotNull FluidCollisionMode fluidCollisionMode)
start
- the start locationdirection
- the ray directionmaxDistance
- the maximum distancefluidCollisionMode
- the fluid collision modenull
if there is no hit@NotNull @NotNull BoundingBox getBoundingBox()
This isn't exact as some blocks Stairs
contain many bounding boxes to establish their complete form.
Also, the box may not be exactly the same as the collision shape (such as
cactus, which is 16/16 of a block with 15/16 collisional bounds).
This method will return an empty bounding box if the geometric shape of
the block is empty (such as air blocks).
@NotNull BlockSoundGroup getSoundGroup()
BlockSoundGroup
for this block.
This object contains the block, step, place, hit, and fall sounds.
Copyright © 2020. All rights reserved.