Struct oc_wasm_opencomputers::inventory::Locked
source · [−]pub struct Locked<'invoker, 'buffer, B: Buffer> { /* private fields */ }Expand description
An inventory controller component on which methods can be invoked.
This type combines an inventory controller 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 Controller::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.
Where a function is declared as taking impl Side, an
AbsoluteSide must be passed if operating on a transposer or an
upgrade module installed in an adapter, while a RelativeSide
must be passed if operating on an upgrade module installed in a robot or drone.
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
sourceimpl<'invoker, 'buffer, B: Buffer> Locked<'invoker, 'buffer, B>
impl<'invoker, 'buffer, B: Buffer> Locked<'invoker, 'buffer, B>
sourcepub async fn get_slot_stack_size(
&mut self,
side: impl Side,
slot: NonZeroU32
) -> Result<u32, Error>
pub async fn get_slot_stack_size(
&mut self,
side: impl Side,
slot: NonZeroU32
) -> Result<u32, Error>
Returns the number of items in an inventory slot.
The slot parameter ranges from 1 to the inventory size.
Errors
sourcepub async fn get_slot_max_stack_size(
&mut self,
side: impl Side,
slot: NonZeroU32
) -> Result<Option<NonZeroU32>, Error>
pub async fn get_slot_max_stack_size(
&mut self,
side: impl Side,
slot: NonZeroU32
) -> Result<Option<NonZeroU32>, Error>
Returns the maximum size of a stack of items, given the item in an inventory slot.
The slot parameter ranges from 1 to the inventory size. If the slot does not contain any
items, None is returned because the maximum stack size depends on the item type.
Errors
sourcepub async fn compare_stacks(
&mut self,
side: impl Side,
slot_a: NonZeroU32,
slot_b: NonZeroU32,
check_nbt: bool
) -> Result<bool, Error>
pub async fn compare_stacks(
&mut self,
side: impl Side,
slot_a: NonZeroU32,
slot_b: NonZeroU32,
check_nbt: bool
) -> Result<bool, Error>
Checks whether two inventory slots contain the same type of item.
The slot_a and slot_b parameters range from 1 to the inventory size. The check_nbt
parameter indicates whether to consider NBT data attached to the item.
Two empty slots are considered equal. An empty slot and a populated slot are considered unequal. Two of the same item with different damage values are considered equal. Two stacks of different numbers of the same item are considered equal.
Errors
sourcepub async fn are_stacks_equivalent(
&mut self,
side: impl Side,
slot_a: NonZeroU32,
slot_b: NonZeroU32
) -> Result<bool, Error>
pub async fn are_stacks_equivalent(
&mut self,
side: impl Side,
slot_a: NonZeroU32,
slot_b: NonZeroU32
) -> Result<bool, Error>
Checks whether two inventory slots contain ore-dictionary-equivalent items.
The slot_a and slot_b parameters range from 1 to the inventory size.
Two empty slots are considered equivalent. An empty slot and a populated slot are considered non-equivalent. A slot is considered equivalent to itself. Otherwise, two slots are considered equivalent if and only if the items in both slots have at least one ore dictionary “ore ID” entry in common.
Errors
sourcepub async fn get_stack_in_slot(
self,
side: impl Side,
slot: NonZeroU32
) -> Result<Option<ItemStack<'buffer>>, Error>
pub async fn get_stack_in_slot(
self,
side: impl Side,
slot: NonZeroU32
) -> Result<Option<ItemStack<'buffer>>, Error>
Returns the item stack in an inventory slot.
The slot parameter ranges from 1 to the inventory size. If the slot does not contain any
items, None is returned.
The strings in the returned item stack point into, and therefore retain ownership of, the
scratch buffer. Consequently, the Locked is consumed and cannot be reused.
Errors
BadComponentBadInventorySlotNoInventoryUnsupportedif detailed item information is disabled in the config file.
sourcepub async fn get_all_stacks(
&mut self,
side: impl Side
) -> Result<Snapshot, Error>
pub async fn get_all_stacks(
&mut self,
side: impl Side
) -> Result<Snapshot, Error>
Returns a snapshot of all the item stacks in an inventory.
Errors
BadComponentNoInventoryUnsupportedif detailed item information is disabled in the config file.
sourcepub async fn get_inventory_name(
self,
side: impl Side
) -> Result<&'buffer str, Error>
pub async fn get_inventory_name(
self,
side: impl Side
) -> Result<&'buffer str, Error>
Returns the internal (Minecraft system) name of an inventory.
For example, this might be minecraft:chest.
The returned string points into, and therefore retains ownership of, the scratch buffer.
Consequently, the Locked is consumed and cannot be reused.
Errors
BadComponentNoInventoryUnsupportedif detailed item information is disabled in the config file.
sourcepub async fn transfer_item<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32
) -> Result<u32, Error>
pub async fn transfer_item<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32
) -> Result<u32, Error>
Moves items between two inventories.
The count value indicates the maximum number of items to move. It is clamped to 64; even
if a stack is larger than 64 items, no more than 64 can be moved in a single operation.
The transfer will only ever move items from one slot in the source inventory; the chosen slot is the first slot from which any items can actually be moved (that is, the first slot that is nonempty and at least one item of which fits in the sink). The transfer may place items into multiple slots in the sink; it first merges items into existing stacks of the same type, then, if any items are left to move, places them into empty slots, in both cases prioritizing based on the order of slots in the sink inventory. The number of items actually moved is returned.
Errors
sourcepub async fn transfer_item_from_slot<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32,
source_slot: NonZeroU32
) -> Result<u32, Error>
pub async fn transfer_item_from_slot<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32,
source_slot: NonZeroU32
) -> Result<u32, Error>
Moves items between two inventories, taking from only a specific slot in the source.
The count value indicates the maximum number of items to move. It is clamped to 64; even
if a stack is larger than 64 items, no more than 64 can be moved in a single operation.
The source_slot parameter ranges from 1 to the source inventory size.
The transfer may place items into multiple slots in the sink; it first merges items into existing stacks of the same type, then, if any items are left to move, places them into empty slots, in both cases prioritizing based on the order of slots in the sink inventory. The number of items actually moved is returned.
Errors
sourcepub async fn transfer_item_from_slot_to_slot<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32,
source_slot: NonZeroU32,
sink_slot: NonZeroU32
) -> Result<u32, Error>
pub async fn transfer_item_from_slot_to_slot<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32,
source_slot: NonZeroU32,
sink_slot: NonZeroU32
) -> Result<u32, Error>
Moves items between two inventories, taking from only a specific slot in the source and storing to only a specific slot in the sink.
The count value indicates the maximum number of items to move. It is clamped to 64; even
if a stack is larger than 64 items, no more than 64 can be moved in a single operation.
The source_slot parameter ranges from 1 to the source inventory size. The sink_slot
parameter ranges from 1 to the sink inventory size.
Errors
sourcepub async fn transfer_fluid<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32
) -> Result<u32, Error>
pub async fn transfer_fluid<SideType: Side>(
&mut self,
source: SideType,
sink: SideType,
count: u32
) -> Result<u32, Error>
Moves fluids between two tanks.
The count value indicates the maximum number of millibuckets to move. The number of
millibuckets moved is returned.
If there is no fluid tank in one of the positions, or if one of the positions is in an
unloaded chunk, Ok(0) is returned. OpenComputers does not consider this to be an error.
Errors
sourcepub async fn get_tank_level(
&mut self,
side: impl Side,
tank: NonZeroU32
) -> Result<u32, Error>
pub async fn get_tank_level(
&mut self,
side: impl Side,
tank: NonZeroU32
) -> Result<u32, Error>
Returns the amount of fluid in a tank, in millibuckets.
The tank parameter ranges from 1 to the number of tanks in the target block.
Errors
sourcepub async fn get_tank_capacity(
&mut self,
side: impl Side,
tank: NonZeroU32
) -> Result<u32, Error>
pub async fn get_tank_capacity(
&mut self,
side: impl Side,
tank: NonZeroU32
) -> Result<u32, Error>
Returns the amount of fluid a tank can hold, in millibuckets.
The tank parameter ranges from 1 to the number of tanks in the target block.
Errors
sourcepub async fn get_fluid_in_tank(
self,
side: impl Side,
tank: NonZeroU32
) -> Result<Option<FluidInTank<'buffer>>, Error>
pub async fn get_fluid_in_tank(
self,
side: impl Side,
tank: NonZeroU32
) -> Result<Option<FluidInTank<'buffer>>, Error>
Returns the fluid in a tank.
The tank parameter ranges from 1 to the number of tanks in the target block.
Errors
BadComponentBadInventorySlotNoInventoryUnsupportedif detailed item information is disabled in the config file.
sourcepub async fn get_fluids_in_tanks(
self,
side: impl Side
) -> Result<Vec<Option<FluidInTank<'buffer>>>, Error>
pub async fn get_fluids_in_tanks(
self,
side: impl Side
) -> Result<Vec<Option<FluidInTank<'buffer>>>, Error>
Returns the fluids in all tanks in a block.
Although tanks are indexed starting from 1 in most situations, for the purpose of this method, the tanks are returned in a vector which is obviously 0-indexed.
Errors
BadComponentNoInventoryUnsupportedif detailed item information is disabled in the config file.
sourcepub async fn get_tank_level_in_slot(
&mut self,
slot: NonZeroU32
) -> Result<u32, Error>
pub async fn get_tank_level_in_slot(
&mut self,
slot: NonZeroU32
) -> Result<u32, Error>
Returns the amount of fluid in a fluid container in the robot or drone’s internal inventory.
The slot parameter ranges from 1 to the internal inventory size.
Errors
sourcepub async fn get_tank_level_in_selected_slot(&mut self) -> Result<u32, Error>
pub async fn get_tank_level_in_selected_slot(&mut self) -> Result<u32, Error>
Returns the amount of fluid in the fluid container in the currently selected slot of the robot or drone’s internal inventory.
Errors
sourcepub async fn get_tank_capacity_in_slot(
&mut self,
slot: NonZeroU32
) -> Result<u32, Error>
pub async fn get_tank_capacity_in_slot(
&mut self,
slot: NonZeroU32
) -> Result<u32, Error>
Returns the total size of a fluid container in the robot or drone’s internal inventory.
The slot parameter ranges from 1 to the internal inventory size.
Errors
sourcepub async fn get_tank_capacity_in_selected_slot(&mut self) -> Result<u32, Error>
pub async fn get_tank_capacity_in_selected_slot(&mut self) -> Result<u32, Error>
Returns the total size of the fluid container in the currently selected slot of the robot or drone’s internal inventory.
If the slot does not contain a fluid container (either because it contains a
non-fluid-container item or because it does not contain anything), None is returned.
Errors
sourcepub async fn get_fluid_in_tank_in_slot(
self,
slot: NonZeroU32
) -> Result<Option<Fluid<'buffer>>, Error>
pub async fn get_fluid_in_tank_in_slot(
self,
slot: NonZeroU32
) -> Result<Option<Fluid<'buffer>>, Error>
Returns information about the fluid in a fluid container in the robot or drone’s internal inventory.
The slot parameter ranges from 1 to the internal inventory size.
If the slot contains an empty fluid container, None is returned.
Errors
BadComponentis returned for any unrecognized error.BadInventorySlotBadItemUnsupported
sourcepub async fn get_fluid_in_tank_in_selected_slot(
self
) -> Result<Option<Fluid<'buffer>>, Error>
pub async fn get_fluid_in_tank_in_selected_slot(
self
) -> Result<Option<Fluid<'buffer>>, Error>
Returns information about the fluid in the fluid container in the selected slot of the robot or drone’s internal inventory.
If the slot contains an empty fluid container, None is returned.
Errors
BadComponentis returned for any unrecognized error.BadItemUnsupported
sourcepub async fn get_fluid_in_internal_tank(
self,
tank: NonZeroU32
) -> Result<Option<Fluid<'buffer>>, Error>
pub async fn get_fluid_in_internal_tank(
self,
tank: NonZeroU32
) -> Result<Option<Fluid<'buffer>>, Error>
Returns information about the fluid in the robot or drone’s specified internal tank.
If the tank is empty, None is returned.
Errors
BadComponentis returned for any unrecognized error.BadInventorySlotUnsupported
sourcepub async fn get_fluid_in_selected_internal_tank(
self
) -> Result<Option<Fluid<'buffer>>, Error>
pub async fn get_fluid_in_selected_internal_tank(
self
) -> Result<Option<Fluid<'buffer>>, Error>
Returns information about the fluid in the robot or drone’s currently selected internal tank.
If the tank is empty, None is returned.
Errors
BadComponentis returned for any unrecognized error.BadInventorySlotUnsupported
sourcepub async fn drain(&mut self, amount: NonZeroU32) -> Result<u32, Error>
pub async fn drain(&mut self, amount: NonZeroU32) -> Result<u32, Error>
Moves fluid from a fluid container in the robot or drone’s currently selected inventory slot into the robot or drone’s currently selected internal tank.
On success, the amount of fluid moved is returned. For certain types of source containers,
this may be larger than amount.
Errors
BadComponentBadItemis returned if the item is not a fluid container, if there is no item in the selected slot, if there is no inventory, or in some cases if the item is empty.Failedis returned in some cases if the item is empty.InventoryFullNoInventoryis returned if there is no tank.
sourcepub async fn fill(&mut self, amount: NonZeroU32) -> Result<u32, Error>
pub async fn fill(&mut self, amount: NonZeroU32) -> Result<u32, Error>
Moves fluid from the robot or drone’s currently selected internal tank into a fluid container in the robot or drone’s currently selected inventory slot.
On success, the amount of fluid moved is returned.
Errors
BadComponentBadItemis returned if the item is not a fluid container, if there is no item in the selected slot, if there is no inventory, or in some cases if the item is full.Failedis returned if the tank is empty, if the item contains a fluid that cannot be mixed with the fluid in the tank, or in some cases if the item is full.NoInventoryis returned if there is no tank.
sourcepub async fn get_stack_in_internal_slot(
self,
slot: NonZeroU32
) -> Result<Option<ItemStack<'buffer>>, Error>
pub async fn get_stack_in_internal_slot(
self,
slot: NonZeroU32
) -> Result<Option<ItemStack<'buffer>>, Error>
Returns the item stack in a robot or drone’s internal inventory slot.
The slot parameter ranges from 1 to the inventory size. If the slot does not contain any
items, None is returned.
The strings in the returned item stack point into, and therefore retain ownership of, the
scratch buffer. Consequently, the Locked is consumed and cannot be reused.
Errors
sourcepub async fn get_stack_in_selected_internal_slot(
self
) -> Result<Option<ItemStack<'buffer>>, Error>
pub async fn get_stack_in_selected_internal_slot(
self
) -> Result<Option<ItemStack<'buffer>>, Error>
Returns the item stack in the robot or drone’s currently selected internal inventory slot.
The strings in the returned item stack point into, and therefore retain ownership of, the
scratch buffer. Consequently, the Locked is consumed and cannot be reused.
Errors
sourcepub async fn is_equivalent_to(
&mut self,
slot: NonZeroU32
) -> Result<bool, Error>
pub async fn is_equivalent_to(
&mut self,
slot: NonZeroU32
) -> Result<bool, Error>
Checks whether a robot or drone’s internal inventory slot contains an ore-dictionary-equivalent item to the currently selected internal inventory slot.
The slot parameter ranges from 1 to the inventory size.
Two empty slots are considered equivalent. An empty slot and a populated slot are considered non-equivalent. A slot is considered equivalent to itself. Otherwise, two slots are considered equivalent if and only if the items in both slots have at least one ore dictionary “ore ID” entry in common.
Errors
sourcepub async fn drop_into_slot(
&mut self,
side: ActionSide,
slot: NonZeroU32,
count: u32,
face: Option<RelativeSide>
) -> Result<(), Error>
pub async fn drop_into_slot(
&mut self,
side: ActionSide,
slot: NonZeroU32,
count: u32,
face: Option<RelativeSide>
) -> Result<(), Error>
Drops items from the robot’s selected slot into a specific slot of an adjacent inventory.
Up to count items from the currently selected slot in the robot’s inventory are moved
into slot slot of the inventory on side side. The face parameter indicates which face
of the destination location to look for inventory slots.
Errors
BadComponentBadInventorySlotInventoryFullFailedis returned if there is no inventory on sideside(or on facefaceof the block on sideside) or if there are no items in the currently selected slot.
sourcepub async fn suck_from_slot(
&mut self,
side: ActionSide,
slot: NonZeroU32,
count: u32,
face: Option<RelativeSide>
) -> Result<u32, Error>
pub async fn suck_from_slot(
&mut self,
side: ActionSide,
slot: NonZeroU32,
count: u32,
face: Option<RelativeSide>
) -> Result<u32, Error>
Sucks up items from a specific slot in an adjacent inventory block into the robot’s internal inventory.
Up to count items from the stack in slot slot in the inventory on side side are
inserted into the robot’s inventory. The face parameter indicates on which face of the
source location to look for inventory slots.
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.
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, including zero if the source stack is empty or there is no space at all
in the robot.
Errors
BadComponentFailedis returned if there is no inventory on sideside(or on facefaceof the block on sideside), or ifslotis greater than the number of slots in the external inventory.
Auto Trait Implementations
impl<'invoker, 'buffer, B> RefUnwindSafe for Locked<'invoker, 'buffer, B> where
B: RefUnwindSafe,
impl<'invoker, 'buffer, B> Send for Locked<'invoker, 'buffer, B> where
B: Send,
impl<'invoker, 'buffer, B> Sync for Locked<'invoker, 'buffer, B> where
B: Sync,
impl<'invoker, 'buffer, B> Unpin for Locked<'invoker, 'buffer, B>
impl<'invoker, 'buffer, B> !UnwindSafe for Locked<'invoker, 'buffer, B>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more