SHOW:
|
|
- or go back to the newest paste.
1 | - | local robot = require("robot") |
1 | + | local robot = require("robot") |
2 | - | local component = require("component") |
2 | + | local component = require("component") |
3 | - | local sides = require("sides") |
3 | + | local sides = require("sides") |
4 | - | local inventory = component.inventory_controller |
4 | + | local inventory = component.inventory_controller |
5 | - | |
5 | + | |
6 | - | local AXE_NAME = "ThaumicTinkerer:ichorAxeGem" |
6 | + | local AXE_NAME = "ThaumicTinkerer:ichorAxeGem" |
7 | - | local HOE_NAME = "EMT:ElectricHoeGrowth" |
7 | + | local HOE_NAME = "EMT:ElectricHoeGrowth" |
8 | - | local SAPLING_NAME = "Forestry:sapling" |
8 | + | local SAPLING_NAME = "minecraft:sapling" |
9 | - | |
9 | + | |
10 | - | local function equipItem(name) |
10 | + | local function equipItem(name) |
11 | - | local emptySlot = 0 |
11 | + | local emptySlot = 0 |
12 | - | for i = 1, robot.inventorySize() do |
12 | + | for i = 1, robot.inventorySize() do |
13 | - | if not inventory.getStackInInternalSlot(i) then |
13 | + | if not inventory.getStackInInternalSlot(i) then |
14 | - | emptySlot = i |
14 | + | emptySlot = i |
15 | - | goto next |
15 | + | goto next |
16 | - | end |
16 | + | end |
17 | - | end |
17 | + | end |
18 | - | |
18 | + | |
19 | - | :: next :: |
19 | + | :: next :: |
20 | - | |
20 | + | |
21 | - | if emptySlot ~= 0 then |
21 | + | if emptySlot ~= 0 then |
22 | - | robot.select(emptySlot) |
22 | + | robot.select(emptySlot) |
23 | - | inventory.equip() |
23 | + | inventory.equip() |
24 | - | else |
24 | + | else |
25 | - | print("Can't find empty slot for sorting") |
25 | + | print("Can't find empty slot for sorting") |
26 | - | goto finish |
26 | + | goto finish |
27 | - | end |
27 | + | end |
28 | - | |
28 | + | |
29 | - | for i = 1, robot.inventorySize() do |
29 | + | for i = 1, robot.inventorySize() do |
30 | - | local item = inventory.getStackInInternalSlot(i) |
30 | + | local item = inventory.getStackInInternalSlot(i) |
31 | - | if item and item.name and item.name == name then |
31 | + | if item and item.name and item.name == name then |
32 | - | robot.select(i) |
32 | + | robot.select(i) |
33 | - | inventory.equip() |
33 | + | inventory.equip() |
34 | - | goto finish |
34 | + | goto finish |
35 | - | end |
35 | + | end |
36 | - | end |
36 | + | end |
37 | - | |
37 | + | |
38 | - | :: finish :: |
38 | + | :: finish :: |
39 | end | |
40 | - | |
40 | + | |
41 | - | local function unload() |
41 | + | local function unload() |
42 | - | |
42 | + | |
43 | - | robot.turnLeft() |
43 | + | robot.turnLeft() |
44 | - | local saplingsDetected = false |
44 | + | local saplingsDetected = false |
45 | - | for i = 1, robot.inventorySize() do |
45 | + | for i = 1, robot.inventorySize() do |
46 | - | local item = inventory.getStackInInternalSlot(i) |
46 | + | local item = inventory.getStackInInternalSlot(i) |
47 | - | if item then |
47 | + | if item then |
48 | - | if item.name and item.name == AXE_NAME then |
48 | + | if item.name and item.name == AXE_NAME then |
49 | - | goto continue |
49 | + | goto continue |
50 | - | elseif item.name and item.name == HOE_NAME then |
50 | + | elseif item.name and item.name == HOE_NAME then |
51 | - | goto continue |
51 | + | goto continue |
52 | - | elseif item.label and item.name == SAPLING_NAME and saplingsDetected == false then |
52 | + | elseif item.label and item.name == SAPLING_NAME and saplingsDetected == false then |
53 | - | saplingsDetected = true |
53 | + | saplingsDetected = true |
54 | - | goto continue |
54 | + | goto continue |
55 | - | else |
55 | + | else |
56 | - | |
56 | + | |
57 | - | robot.select(i) |
57 | + | robot.select(i) |
58 | - | inventory.dropIntoSlot(sides.front, i) |
58 | + | inventory.dropIntoSlot(sides.front, i) |
59 | - | end |
59 | + | end |
60 | - | end |
60 | + | end |
61 | - | |
61 | + | |
62 | - | :: continue :: |
62 | + | :: continue :: |
63 | - | end |
63 | + | end |
64 | - | |
64 | + | |
65 | - | robot.turnRight() |
65 | + | robot.turnRight() |
66 | end | |
67 | - | |
67 | + | |
68 | - | local function charge() |
68 | + | local function charge() |
69 | - | |
69 | + | |
70 | - | local hoeSlot = -1 |
70 | + | local hoeSlot = -1 |
71 | - | for i = 1, robot.inventorySize() do |
71 | + | for i = 1, robot.inventorySize() do |
72 | - | local item = inventory.getStackInInternalSlot(i) |
72 | + | local item = inventory.getStackInInternalSlot(i) |
73 | - | if item and item.name and item.name == HOE_NAME and item.charge and item.charge <= 2000 then |
73 | + | if item and item.name and item.name == HOE_NAME and item.charge and item.charge <= 2000 then |
74 | - | hoeSlot = i |
74 | + | hoeSlot = i |
75 | - | goto charge |
75 | + | goto charge |
76 | - | end |
76 | + | end |
77 | - | end |
77 | + | end |
78 | - | |
78 | + | |
79 | - | :: charge :: |
79 | + | :: charge :: |
80 | - | |
80 | + | |
81 | - | if hoeSlot ~= -1 then |
81 | + | if hoeSlot ~= -1 then |
82 | - | robot.turnRight() |
82 | + | robot.turnRight() |
83 | - | |
83 | + | |
84 | - | print("hoe charging started") |
84 | + | print("hoe charging started") |
85 | - | robot.select(hoeSlot) |
85 | + | robot.select(hoeSlot) |
86 | - | inventory.dropIntoSlot(sides.front, 1) |
86 | + | inventory.dropIntoSlot(sides.front, 1) |
87 | - | os.sleep(15) |
87 | + | os.sleep(15) |
88 | - | inventory.suckFromSlot(sides.front, 1) |
88 | + | inventory.suckFromSlot(sides.front, 1) |
89 | - | print("hoe charging finished") |
89 | + | print("hoe charging finished") |
90 | - | |
90 | + | |
91 | - | robot.turnLeft() |
91 | + | robot.turnLeft() |
92 | - | end |
92 | + | end |
93 | - | |
93 | + | |
94 | end | |
95 | - | |
95 | + | |
96 | - | local function safeMovement(func) |
96 | + | local function safeMovement(func) |
97 | - | local result, reason = func() |
97 | + | local result, reason = func() |
98 | - | while not result do |
98 | + | while not result do |
99 | - | print(result, result) |
99 | + | print(result, result) |
100 | - | result, reason = func() |
100 | + | result, reason = func() |
101 | - | end |
101 | + | end |
102 | end | |
103 | - | |
103 | + | |
104 | - | local function plantSapling() |
104 | + | local function plantSapling() |
105 | - | equipItem(SAPLING_NAME) |
105 | + | equipItem(SAPLING_NAME) |
106 | - | |
106 | + | |
107 | - | safeMovement(robot.up) |
107 | + | safeMovement(robot.up) |
108 | - | safeMovement(robot.forward) |
108 | + | safeMovement(robot.forward) |
109 | - | robot.useDown() |
109 | + | robot.useDown() |
110 | - | safeMovement(robot.back) |
110 | + | safeMovement(robot.back) |
111 | - | safeMovement(robot.down) |
111 | + | safeMovement(robot.down) |
112 | - | print("=========================") |
112 | + | print("=========================") |
113 | end | |
114 | - | |
114 | + | |
115 | - | local function growSapling() |
115 | + | local function growSapling() |
116 | - | equipItem(HOE_NAME) |
116 | + | equipItem(HOE_NAME) |
117 | - | |
117 | + | |
118 | - | for i = 1, 10 do |
118 | + | for i = 1, 10 do |
119 | - | robot.use(sides.front) |
119 | + | robot.use(sides.front) |
120 | - | os.sleep(0.2) |
120 | + | os.sleep(0.2) |
121 | - | end |
121 | + | end |
122 | end | |
123 | - | |
123 | + | |
124 | - | local function chopSapling() |
124 | + | local function chopSapling() |
125 | - | equipItem(AXE_NAME) |
125 | + | equipItem(AXE_NAME) |
126 | - | |
126 | + | |
127 | - | robot.swing() |
127 | + | robot.swing() |
128 | - | os.sleep(0.2) |
128 | + | os.sleep(0.2) |
129 | end | |
130 | - | |
130 | + | |
131 | - | local function suckItems() |
131 | + | local function suckItems() |
132 | - | os.sleep(10) |
132 | + | os.sleep(10) |
133 | - | robot.suck() |
133 | + | robot.suck() |
134 | - | robot.suckUp() |
134 | + | robot.suckUp() |
135 | end | |
136 | - | |
136 | + | |
137 | - | while true do |
137 | + | while true do |
138 | - | unload() |
138 | + | unload() |
139 | - | charge() |
139 | + | charge() |
140 | - | plantSapling() |
140 | + | plantSapling() |
141 | - | growSapling() |
141 | + | growSapling() |
142 | - | chopSapling() |
142 | + | chopSapling() |
143 | - | suckItems() |
143 | + | suckItems() |
144 | end |