pub struct Locked<'invoker, 'buffer, B: Buffer> { /* private fields */ }
Expand description
A robot component on which methods can be invoked.
This type combines a robot address, an Invoker
that can be used to make method calls, and a
scratch buffer used to perform CBOR encoding and decoding. A value of this type can be created
by calling Robot::lock
, and it can be dropped to return the borrow of the invoker and
buffer to the caller so they can be reused for other purposes.
The 'invoker
lifetime is the lifetime of the invoker. The 'buffer
lifetime is the lifetime
of the buffer. The B
type is the type of scratch buffer to use.
Implementations§
Source§impl<'invoker, 'buffer, B: Buffer> Locked<'invoker, 'buffer, B>
impl<'invoker, 'buffer, B: Buffer> Locked<'invoker, 'buffer, B>
Sourcepub async fn get_light_colour(&mut self) -> Result<Rgb, Error>
pub async fn get_light_colour(&mut self) -> Result<Rgb, Error>
Sourcepub async fn durability(&mut self) -> Result<Option<f64>, Error>
pub async fn durability(&mut self) -> Result<Option<f64>, Error>
Returns the durability of the equipped tool, or None
if no tool is equipped or the
equipped tool does not have a concept of durability.
The durability value, if available, is a number between 0 and 1.
§Errors
Sourcepub async fn move_robot(
&mut self,
direction: MoveDirection,
) -> Result<(), Error>
pub async fn move_robot( &mut self, direction: MoveDirection, ) -> Result<(), Error>
Sourcepub async fn turn(&mut self, direction: Rotation) -> Result<(), Error>
pub async fn turn(&mut self, direction: Rotation) -> Result<(), Error>
Sourcepub async fn swing(
&mut self,
side: ActionSide,
face: Option<RelativeSide>,
sneak: bool,
) -> Result<ToolHit, Error>
pub async fn swing( &mut self, side: ActionSide, face: Option<RelativeSide>, sneak: bool, ) -> Result<ToolHit, Error>
Left-clicks the currently equipped tool on an adjacent block or space.
The side
parameter indicates where to swing the tool, relative the robot’s current facing
direction. The face
parameter indicates which face of the target location to aim at. The
sneak
parameter indicates whether or not to sneak while operating the tool.
§Errors
BadComponent
BadItem
is returned if the block in the target location is too hard for the equipped tool to break, or the tool is of the wrong kind (for example, a shovel swinging at cobblestone).TooManyDescriptors
Sourcepub async fn use_item(
&mut self,
side: ActionSide,
face: Option<RelativeSide>,
sneak: bool,
duration: f64,
) -> Result<ActivateResult, Error>
pub async fn use_item( &mut self, side: ActionSide, face: Option<RelativeSide>, sneak: bool, duration: f64, ) -> Result<ActivateResult, Error>
Right-clicks the currently equipped item on an adjacent block or space.
The side
parameter indicates where to use the item, relative the robot’s current facing
direction. The face
parameter indicates which face of the target location to aim at. The
sneak
parameter indicates whether or not to sneak while operating the tool. The
duration
parameter indicates how long to hold down the right mouse button.
§Errors
BadComponent
TooManyDescriptors
Failed
is returned if the item is not usable (for example, if it is a piece of coal), is usable on certain entities but such entities are not present (for example, if it is a shears and there is nothing in front of the robot or the entity in front of the robot is a zombie), or is a placeable block but there is no adjacent block on which to mount it and the robot is not equipped with an angel upgrade.
Sourcepub async fn place(
&mut self,
side: ActionSide,
face: Option<RelativeSide>,
sneak: bool,
) -> Result<(), Error>
pub async fn place( &mut self, side: ActionSide, face: Option<RelativeSide>, sneak: bool, ) -> Result<(), Error>
Places one of the currently selected item into the world as a block.
The side
parameter indicates in which location, relative to the robot’s current facing
direction, the item should be placed. The face
parameter indicates on which face of the
target location the item should be placed (for example, for a lever or torch, on which
adjacent surface the item should be mounted), again relative to the robot’s current facing
direction; or is set to None
to try all possible faces. The sneak
parameter indicates
whether or not to sneak while placing the item.
§Errors
BadComponent
BadItem
is returned if there is no item selected.TooManyDescriptors
Failed
is returned if the selected item does not have a placeable block form (e.g. it is a tool instead); the target location is obstructed by an existing block; there is no existing block adjacent to the target placement location and the robot is not equipped with an angel upgrade; orface
is provided, there is no existing block adjacent to the target placement location on the specified side, and the robot is not equipped with an angel upgrade;face
is provided and points back towards the robot; or there is not enough energy.
Sourcepub async fn detect(&mut self, side: ActionSide) -> Result<BlockContent, Error>
pub async fn detect(&mut self, side: ActionSide) -> Result<BlockContent, Error>
Checks what’s present in a specified direction.
The side
parameter indicates which space, relative to the robot’s current facing
direction, to scan.
§Errors
Sourcepub async fn inventory_size(&mut self) -> Result<u32, Error>
pub async fn inventory_size(&mut self) -> Result<u32, Error>
Sourcepub async fn selected(&mut self) -> Result<NonZeroU32, Error>
pub async fn selected(&mut self) -> Result<NonZeroU32, Error>
Returns the currently selected inventory slot number.
§Errors
Sourcepub async fn count(&mut self, slot: NonZeroU32) -> Result<u32, Error>
pub async fn count(&mut self, slot: NonZeroU32) -> Result<u32, Error>
Returns the number of items in an inventory slot.
§Errors
Sourcepub async fn count_selected(&mut self) -> Result<u32, Error>
pub async fn count_selected(&mut self) -> Result<u32, Error>
Returns the number of items in the currently selected inventory slot.
If the robot does not have an inventory, this function returns 0.
§Errors
Sourcepub async fn space(&mut self, slot: NonZeroU32) -> Result<u32, Error>
pub async fn space(&mut self, slot: NonZeroU32) -> Result<u32, Error>
Returns the number of items that can be added to an inventory slot.
§Errors
Sourcepub async fn space_selected(&mut self) -> Result<u32, Error>
pub async fn space_selected(&mut self) -> Result<u32, Error>
Returns the number of items that can be added to the currently selected inventory slot.
If the robot does not have an inventory, this function returns 64.
§Errors
Sourcepub async fn compare_to(
&mut self,
other_slot: NonZeroU32,
nbt: bool,
) -> Result<bool, Error>
pub async fn compare_to( &mut self, other_slot: NonZeroU32, nbt: bool, ) -> Result<bool, Error>
Returns whether or not the currently selected inventory slot contains the same item as the specified inventory slot.
The nbt
parameter indicates whether to consider NBT data during the comparison. Two empty
slots are considered equal to each other but not to any nonempty slot. Between two nonempty
slots, the sizes of the stacks do not matter; a slot with one torch and a slot with two
torches are considered equal.
§Errors
Sourcepub async fn transfer_to(
&mut self,
target_slot: NonZeroU32,
amount: u32,
) -> Result<(), Error>
pub async fn transfer_to( &mut self, target_slot: NonZeroU32, amount: u32, ) -> Result<(), Error>
Moves items from the currently selected inventory slot to the specified inventory slot.
The amount
parameter indicates the maximum number of items to transfer. If the target
slot is empty, then the lesser of amount
and the number of items available is moved. If
the selected and target slots contain the same type of item, then the lesser of amount
,
the number of items available, and the remaining space in the target is moved. If the
target slot contains a different type of item and amount
is greater than or equal to the
number of items in the selected slot, then the two stacks are swapped.
§Errors
BadComponent
BadInventorySlot
TooManyDescriptors
Failed
is returned ifamount
was nonzero but no items could be moved (because the source stack is empty, the target stack is of the same type and full, or the target stack is of a different type andamount
is less than the size of the source stack and therefore the stacks cannot be swapped).
Sourcepub async fn compare(
&mut self,
side: ActionSide,
fuzzy: bool,
) -> Result<bool, Error>
pub async fn compare( &mut self, side: ActionSide, fuzzy: bool, ) -> Result<bool, Error>
Compares a block in the world with the selected inventory slot.
The fuzzy
parameter, when true
, indicates that the comparison should ignore item
subtypes (for example, dirt and coarse dirt are considered equal under fuzzy comparison
rules). An empty itemstack is considered unequal to any block, and an air block is
considered unequal to any itemstack.
§Errors
Sourcepub async fn drop(&mut self, side: ActionSide, count: u32) -> Result<(), Error>
pub async fn drop(&mut self, side: ActionSide, count: u32) -> Result<(), Error>
Drops items from the robot’s selected slot into the world as an itemstack entity or into an adjacent inventory.
If a block with an inventory is present on the specified side, up to count
items from the
currently selected slot are inserted into the inventory following the usual item insertion
rules. If there are fewer than count
items available or the inventory does not have space
to hold count
items, then fewer items are moved.
If no inventory is present on the specified side, up to count
items are dropped into the
world as an itemstack entity. If there are fewer than count
items available, then a
smaller stack is dropped.
§Errors
Sourcepub async fn suck(&mut self, side: ActionSide, count: u32) -> Result<u32, Error>
pub async fn suck(&mut self, side: ActionSide, count: u32) -> Result<u32, Error>
Sucks up items from an itemstack entity or an adjacent inventory block.
If a block with an inventory is present on the specified side, up to count
items from a
single stack in that inventory are inserted into the robot’s inventory.
If no inventory is present on the specified side, one itemstack entity (of any size,
ignoring count
) is picked up from the world.
The sucked items are placed into the robot’s inventory, initially into the currently selected slot, then into slots after it, then wrapping around to slots before it, as necessary to hold all the sucked items. If there is not enough space to hold the items, then the items that cannot be held are left behind in their original location.
If all the robot’s inventory slots contain items, preventing a new type of item from being added, external inventory slots or itemstack entities are selected to match an item type already present in the robot. Otherwise, the first populated inventory slot, or an arbitrary itemstack entity, is selected.
On success, the number of items actually moved is returned, which may be less than count
if the source stack does not have that many items or if that many items do not fit into the
robot’s inventory, or may be more than count
if the source is an itemstack entity because
count
is ignored.
§Errors
BadComponent
TooManyDescriptors
Failed
is returned if there are no items in the specified direction, there is no space to move the items into (due to either number or type), or the adjacent inventory does not allow items to be removed.
Sourcepub async fn tank_count(&mut self) -> Result<u32, Error>
pub async fn tank_count(&mut self) -> Result<u32, Error>
Returns the number of internal fluid tanks.
This is typically equal to the number of tank upgrades (not tank controller upgrades) installed in the robot.
§Errors
Sourcepub async fn selected_tank(&mut self) -> Result<NonZeroU32, Error>
pub async fn selected_tank(&mut self) -> Result<NonZeroU32, Error>
Returns the currently selected internal fluid tank number.
If the robot has no tanks at all, this function returns 1.
§Errors
Sourcepub async fn select_tank(&mut self, tank: NonZeroU32) -> Result<(), Error>
pub async fn select_tank(&mut self, tank: NonZeroU32) -> Result<(), Error>
Sourcepub async fn tank_level(&mut self, tank: NonZeroU32) -> Result<u32, Error>
pub async fn tank_level(&mut self, tank: NonZeroU32) -> Result<u32, Error>
Returns the number of millibuckets of fluid in an internal fluid tank.
§Errors
Sourcepub async fn tank_level_selected(&mut self) -> Result<u32, Error>
pub async fn tank_level_selected(&mut self) -> Result<u32, Error>
Returns the number of millibuckets of fluid in the currently selected internal fluid tank.
If the robot does not have any tanks, this function returns 0.
§Errors
Sourcepub async fn tank_space(&mut self, tank: NonZeroU32) -> Result<u32, Error>
pub async fn tank_space(&mut self, tank: NonZeroU32) -> Result<u32, Error>
Returns the number of millibuckets of fluid that can be added to an internal fluid tank.
§Errors
Sourcepub async fn tank_space_selected(&mut self) -> Result<u32, Error>
pub async fn tank_space_selected(&mut self) -> Result<u32, Error>
Returns the number of millibuckets of fluid that can be added to the currently selected internal fluid tank.
If the robot does not have any tanks, this function returns 0.
§Errors
Sourcepub async fn compare_fluid_to(
&mut self,
other_tank: NonZeroU32,
) -> Result<bool, Error>
pub async fn compare_fluid_to( &mut self, other_tank: NonZeroU32, ) -> Result<bool, Error>
Returns whether or not the currently selected internal fluid tank contains the same type of fluid as the specified internal fluid tank.
Two empty tanks are considered equal. An empty tank is not equal to any nonempty tank.
§Errors
Sourcepub async fn transfer_fluid_to(
&mut self,
target_tank: NonZeroU32,
amount: u32,
) -> Result<(), Error>
pub async fn transfer_fluid_to( &mut self, target_tank: NonZeroU32, amount: u32, ) -> Result<(), Error>
Moves fluid from the currently selected internal fluid tank to the specified internal fluid tank.
The amount
parameter indicates the maximum number of millibuckets to transfer. If the
target tank is able to hold any fluid of the type held in the source tank, then the minimum
of amount
, the amount of fluid in the source tank, and the amount of space in the target
tank is moved. If the target tank is not able to hold any of the fluid type held in the
source tank (either because it is full or because the fluids are of different types), and
if amount
is greater than or equal to the amount of fluid in the source tank, then the
two tanks’ contents are swapped. If the source tank is empty, the entire destination tank
is moved to the source tank (i.e. the tanks’s contents are swapped).
§Errors
BadComponent
BadInventorySlot
TooManyDescriptors
Failed
is returned if the requested tank number is greater than the tank count, oramount
was nonzero but no fluid could be moved (because the source tank is empty, the target tank is of the same type and full, or the target tank is of a different type andamount
is less than the size of the source tank and therefore the fluids cannot be swapped).
Sourcepub async fn compare_fluid(
&mut self,
side: ActionSide,
tank: NonZeroU32,
) -> Result<bool, Error>
pub async fn compare_fluid( &mut self, side: ActionSide, tank: NonZeroU32, ) -> Result<bool, Error>
Returns whether or not the currently selected internal fluid tank contains the same type of fluid as a tank in an external block.
The tank
parameter selects the tank within the external block. An empty tank (or
nonexistent tank, in the case of a robot without any internal tanks) is considered unequal
to everything, including another empty tank.
§Errors
BadComponent
BadInventorySlot
is returned if there is no fluid-containing block on the specified side or if thetank
parameter is greater than the number of tanks in the block and the selected internal tank is nonempty, but only if the selected tank is non-empty.TooManyDescriptors
Sourcepub async fn drain(
&mut self,
side: ActionSide,
amount: u32,
) -> Result<u32, Error>
pub async fn drain( &mut self, side: ActionSide, amount: u32, ) -> Result<u32, Error>
Moves fluid from an external block’s fluid tank to the currently selected internal fluid tank.
On success, the amount of fluid moved is the minimum of amount
, the amount of fluid in
the source tank, and the amount of space in the target tank, and this number is returned.
§Errors
BadComponent
BadItem
is returned if the destination already contains an incompatible fluid.InventoryFull
NoInventory
is returned if the robot does not contain any tanks.TooManyDescriptors
Sourcepub async fn fill(
&mut self,
side: ActionSide,
amount: u32,
) -> Result<u32, Error>
pub async fn fill( &mut self, side: ActionSide, amount: u32, ) -> Result<u32, Error>
Moves fluid from the currently selected internal fluid tank to an external block.
On success, the amount of fluid moved is the minimum of amount
, the amount of fluid in
the source tank, and the amount of space in the target tank, and this number is returned.
§Errors
BadComponent
BadItem
is returned if the destination already contains an incompatible fluid.InventoryFull
NoInventory
is returned if the robot does not contain any tanks.NoItem
is returned if the source tank is empty andamount
is nonzero.TooManyDescriptors