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
142
143
144
145
146
147
148
149
150
151
152
153
154
//! The transposer device and its associated types
use std::{convert::Infallible, num::NonZeroU32};
use uuid::Uuid;
use crate::{
client::{DeviceBase, HlapiClient, HlapiClientError},
devices::{ItemStack, Side, TankContentInfo},
};
#[derive(Debug, Clone)]
/// A transposer device
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/transposer.html)
pub struct Transposer {
client: HlapiClient,
uuid: Uuid,
}
impl Transposer {
/// Gets the contents of the given tank in the container to the specified side.
/// Returns [`None`] if the tank is empty.
pub fn get_fluid_in_tank(
&self,
side: Side,
tank: u32,
) -> Result<Option<TankContentInfo>, HlapiClientError> {
Ok(self
.call("getFluidInTank", &[&side as _, &tank as _], &[])?
.0)
}
/// Gets the number of millibuckets the given tank in the container to the specified side can hold.
pub fn get_fluid_tank_capacity(&self, side: Side, tank: u32) -> Result<u32, HlapiClientError> {
Ok(self
.call("getFluidTankCapacity", &[&side as _, &tank as _], &[])?
.0)
}
/// Gets the number of tanks in the fluid container to the specified side.
/// Returns [`None`] if there is no container to that side.
pub fn get_fluid_tank_count(&self, side: Side) -> Result<Option<NonZeroU32>, HlapiClientError> {
let raw = self.call("getFluidTankCount", &[&side as _], &[])?.0;
Ok(NonZeroU32::new(raw))
}
/// Gets the number of slots in the inventory to the specified side.
/// Returns [`None`] if there is no inventory to that side.
pub fn get_item_slot_count(&self, side: Side) -> 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 can hold.
pub fn get_item_slot_limit(&self, side: Side, slot: u32) -> Result<u32, HlapiClientError> {
Ok(self
.call("getItemSlotLimit", &[&side as _, &slot as _], &[])?
.0)
}
/// Gets the contents of the given slot in the inventory to the specified side.
/// Returns [`None`] if the slot is empty.
pub fn get_item_stack_in_slot(
&self,
side: Side,
slot: u32,
) -> Result<Option<ItemStack>, HlapiClientError> {
Ok(self
.call("getItemStackInSlot", &[&side as _, &slot as _], &[])?
.0)
}
/// Moves fluid from one container to another, up to the maximum amount in millibuckets given.
/// If there is no container on the source side, it will try to drain fluid from the world in
/// increments of one bucket, and if there is no container on the destination side, it will try
/// to dump fluid into the world in increments of one bucket. Returns the actual amount moved.
pub fn move_fluid(
&self,
source: Side,
destination: Side,
max_amount: u32,
) -> Result<u32, HlapiClientError> {
Ok(self
.call(
"moveFluid",
&[&source as _, &destination as _, &max_amount as _],
&[],
)?
.0)
}
/// Moves items from one container to another, up to the maximum count given.
/// If there is no inventory on the source side, it will try to pick up items from the world,
/// and if there is no inventory on the destination side, it will drop items into the world.
/// Returns the actual count moved.
pub fn move_items(
&self,
source: Side,
destination: Side,
max_count: u32,
) -> Result<u32, HlapiClientError> {
Ok(self
.call(
"moveItems",
&[&source as _, &destination as _, &max_count as _],
&[],
)?
.0)
}
/// Moves items from one slot in a container to another slot in a possibly different container,
/// up to the maximum count given. Returns the actual count moved.
pub fn move_items_slot(
&self,
source: Side,
source_slot: u32,
destination: Side,
destination_slot: u32,
max_count: u32,
) -> Result<u32, HlapiClientError> {
Ok(self
.call(
"moveItems",
&[
&source as _,
&source_slot as _,
&destination as _,
&destination_slot as _,
&max_count as _,
],
&[],
)?
.0)
}
}
impl DeviceBase for Transposer {
const TYPE: &'static str = "transposer";
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
}
}