namespace Minecraft.Server.FourKit.Block;
///
/// Represents a block. This is a live object, and only one Block may exist for
/// any given location in a world.
///
public class Block
{
private readonly World _world;
private readonly int _x;
private readonly int _y;
private readonly int _z;
internal Block(World world, int x, int y, int z)
{
_world = world;
_x = x;
_y = y;
_z = z;
}
///
/// Gets the Location of the block.
///
/// Location of the block.
public Location getLocation()
{
return new Location(_world, _x, _y, _z, 0f, 0f);
}
///
/// Gets the type of this block.
///
/// Block type.
public Material getType()
{
int id = getTypeId();
return Enum.IsDefined(typeof(Material), id) ? (Material)id : Material.AIR;
}
///
/// Gets the type ID of this block.
///
/// Block type ID.
public int getTypeId()
{
if (NativeBridge.GetTileId != null)
return NativeBridge.GetTileId(_world.getDimensionId(), _x, _y, _z);
return 0;
}
///
/// Gets the world which contains this Block.
///
/// World containing this block.
public World getWorld() => _world;
///
/// Gets the x-coordinate of this block.
///
/// X-coordinate.
public int getX() => _x;
///
/// Gets the y-coordinate of this block.
///
/// Y-coordinate.
public int getY() => _y;
///
/// Gets the z-coordinate of this block.
///
/// Z-coordinate.
public int getZ() => _z;
///
/// Sets the type of this block.
///
/// Material to change this block to.
public void setType(Material type)
{
setTypeId((int)type);
}
///
/// Sets the type ID of this block.
///
/// Type ID to change this block to.
/// Whether the change was successful.
public bool setTypeId(int type)
{
NativeBridge.SetTile?.Invoke(_world.getDimensionId(), _x, _y, _z, type, 0);
return true;
}
///
/// Gets the metadata value for this block.
///
/// Block specific metadata.
public byte getData()
{
return (byte)NativeBridge.GetTileData(_world.getDimensionId(), _x, _y, _z);
}
///
/// Sets the metadata value for this block.
///
/// New block specific metadata.
public void setData(byte data)
{
NativeBridge.SetTileData?.Invoke(_world.getDimensionId(), _x, _y, _z, data);
}
///
/// Breaks the block and spawns items as if a player had digged it.
///
/// true if the block was destroyed.
public bool breakNaturally()
{
if (NativeBridge.BreakBlock != null)
return NativeBridge.BreakBlock(_world.getDimensionId(), _x, _y, _z) != 0;
return false;
}
}