1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::{convert::Infallible, num::NonZeroU32};
use uuid::Uuid;
use crate::{
client::{DeviceBase, HlapiClient, HlapiClientError},
devices::{ItemStack, robot::RobotSide},
};
#[derive(Debug, Clone)]
/// The device for the inventory operations module
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/inventory_operations.html)
pub struct InventoryOperations {
client: HlapiClient,
uuid: Uuid,
}
impl InventoryOperations {
/// Tries to drop the given number of items to the specified side, defaulting to [`RobotSide::Front`].
/// Items are dropped into the world if there is no inventory to that side. Returns the actual number of
/// items dropped.
pub fn drop(&self, count: u32, side: Option<RobotSide>) -> Result<u32, HlapiClientError> {
Ok(self.call("drop", &[&count as _, &side as _], &[])?.0)
}
/// Tries to drop the given number of items into the given slot of the inventory to the specified side,
/// defaulting to [`RobotSide::Front`]. Returns the actual number of items dropped.
pub fn drop_into(
&self,
slot: u32,
count: u32,
side: Option<RobotSide>,
) -> Result<u32, HlapiClientError> {
Ok(self
.call("dropInto", &[&slot as _, &count as _, &side as _], &[])?
.0)
}
/// Gets the number of slots in the inventory to the specified side, defaulting to [`RobotSide::Front`].
/// Returns [`None`] if there is no inventory to that side.
pub fn get_item_slot_count(
&self,
side: Option<RobotSide>,
) -> Result<Option<NonZeroU32>, HlapiClientError> {
let raw = self.call("getItemSlotCount", &[&side as _], &[])?.0;
Ok(NonZeroU32::new(raw))
}
/// Gets the number of items the given slot in the inventory to the specified side, defaulting to
/// [`RobotSide::Front`], can hold.
pub fn get_item_slot_limit(
&self,
slot: u32,
side: Option<RobotSide>,
) -> Result<u32, HlapiClientError> {
Ok(self
.call("getItemSlotLimit", &[&slot as _, &side as _], &[])?
.0)
}
/// Gets the contents of the given slot in the inventory to the specified side, defaulting to
/// [`RobotSide::Front`]. Returns [`None`] if the slot is empty.
pub fn get_item_stack_in_slot(
&self,
slot: u32,
side: Option<RobotSide>,
) -> Result<Option<ItemStack>, HlapiClientError> {
Ok(self
.call("getItemStackInSlot", &[&slot as _, &side as _], &[])?
.0)
}
/// Moves up to the given number of items from one internal inventory slot to another, returning
/// the actual count of items moved.
pub fn move_internal(
&self,
from: u32,
into: u32,
max_count: u32,
) -> Result<u32, HlapiClientError> {
Ok(self
.call("move", &[&from as _, &into as _, &max_count as _], &[])?
.0)
}
/// Moves up to the given number of items from the container in the selected slot to the given
/// internal slot, returning
/// the actual count of items moved.
pub fn move_from(&self, into: u32, max_count: u32) -> Result<u32, HlapiClientError> {
Ok(self
.call("moveFrom", &[&into as _, &max_count as _], &[])?
.0)
}
/// Moves up to the given number of items from the given internal slot to the container in the
/// selected slot, returning the actual count of items moved.
pub fn move_into(&self, from: u32, max_count: u32) -> Result<u32, HlapiClientError> {
Ok(self
.call("moveInto", &[&from as _, &max_count as _], &[])?
.0)
}
/// Tries to take up to the given number of items from the specified side, defaulting to
/// [`RobotSide::Front`]. Items are taken from the world if there is no inventory to that side.
/// Returns the actual count of items taken.
pub fn take(&self, max_count: u32, side: Option<RobotSide>) -> Result<u32, HlapiClientError> {
Ok(self.call("take", &[&max_count as _, &side as _], &[])?.0)
}
/// Tries to take up to the given number of items from the given slot of the inventory to the
/// specified side, defaulting to [`RobotSide::Front`]. Returns the actual count of items taken.
pub fn take_from(
&self,
slot: u32,
max_count: u32,
side: Option<RobotSide>,
) -> Result<u32, HlapiClientError> {
Ok(self
.call("takeFrom", &[&slot as _, &max_count as _, &side as _], &[])?
.0)
}
}
impl DeviceBase for InventoryOperations {
const TYPE: &'static str = "inventory_operations";
type Event = Infallible;
fn new(client: HlapiClient, uuid: Uuid) -> Result<Self, HlapiClientError> {
Ok(Self { client, uuid })
}
fn uuid_base(&self) -> Uuid {
self.uuid
}
fn client(&self) -> &HlapiClient {
&self.client
}
}