1+ ---
2+ --- Advanced Peripherals ME Bridge transfer tests
3+ --- Covers `isConnected`, `getEnergyUsage`, `getItem`, `exportItemToPeripheral`, `exportItem`,
4+ --- `importItem`, `importItemFromPeripheral`
5+ ---
6+
7+ sleep (4 )
8+ bridge = peripheral .wrap (" meBridge_3" )
9+ chest = peripheral .wrap (" minecraft:chest_2" )
10+ test .assert (bridge , " Peripheral not found" )
11+ test .assert (chest , " Chest not found" )
12+
13+ isOnline = bridge .isConnected ()
14+ test .assert (isOnline , " Bridge is not connected/system is not online" )
15+
16+ energyUsage = bridge .getEnergyUsage ()
17+ test .assert (energyUsage > 17 , tostring (energyUsage ) .. " Consumption does not seem right" )
18+
19+ planksFilter = {name = " minecraft:oak_planks" , count = 5 }
20+ logFilter = {name = " minecraft:oak_log" , count = 8 }
21+
22+ exported , err = bridge .exportItemToPeripheral (planksFilter , peripheral .getName (chest ))
23+ test .assert (exported == 5 , " Export failed " .. (err or " " ))
24+
25+ planksItem = bridge .getItem (planksFilter )
26+ test .assert (planksItem .amount == 251 , " We should have 251 planks" )
27+
28+ chestPlanks = nil
29+ for slot , item in pairs (chest .list ()) do
30+ if item .name == " minecraft:oak_planks" then
31+ chestPlanks = item
32+ end
33+ end
34+
35+ test .assert (chestPlanks , " Planks not found in chest" )
36+ test .assert (chestPlanks .count == 5 , " We should have 5 planks in the chest" )
37+
38+ exported , err = bridge .exportItem (planksFilter , " front" )
39+ test .assert (exported == 5 , " Export failed " .. (err or " " ))
40+
41+ planksItem = bridge .getItem (planksFilter )
42+ test .assert (planksItem .amount == 246 , " We should have 246 planks" )
43+
44+ for slot , item in pairs (chest .list ()) do
45+ if item .name == " minecraft:oak_planks" then
46+ chestPlanks = item
47+ end
48+ end
49+
50+ test .assert (chestPlanks , " Planks not found in chest" )
51+ test .assert (chestPlanks .count == 10 , " We should have 5 planks in the chest" )
52+
53+ imported , err = bridge .importItemFromPeripheral (logFilter , peripheral .getName (chest ))
54+ test .assert (imported == 8 , " import failed " .. (err or " " ))
55+
56+ logsItem = bridge .getItem (logFilter )
57+ test .assert (logsItem .amount == 264 , " We should have 264 logs" )
58+
59+ chestLogs = nil
60+ for slot , item in pairs (chest .list ()) do
61+ if item .name == " minecraft:oak_log" then
62+ chestLogs = item
63+ end
64+ end
65+
66+ test .assert (chestLogs , " Logs not found in chest" )
67+ test .assert (chestLogs .count == 56 , " We should have 56 logs in the chest" )
68+
69+ imported , err = bridge .importItem (logFilter , " south" )
70+ test .assert (imported == 8 , " import failed " .. (err or " " ))
71+
72+ logsItem = bridge .getItem (logFilter )
73+ test .assert (logsItem .amount == 272 , " We should have 272 logs" )
74+
75+ chestLogs = nil
76+ for slot , item in pairs (chest .list ()) do
77+ if item .name == " minecraft:oak_log" then
78+ chestLogs = item
79+ end
80+ end
81+
82+ test .assert (chestLogs , " Logs not found in chest" )
83+ test .assert (chestLogs .count == 48 , " We should have 48 logs in the chest" )
0 commit comments