SHOW:
|
|
- or go back to the newest paste.
| 1 | rednet.open("right")
| |
| 2 | os.loadAPI("button")
| |
| 3 | local turtleID = 98 | |
| 4 | ||
| 5 | -- essentia is an array. The array elements are defined by the name of the aspect. The value of that element is the amount | |
| 6 | -- of essentia in a jar. For example: essentia["ordo"]=21 means the ordo jar has 21 essentia | |
| 7 | local essentia = {}
| |
| 8 | -- ejar is an array of the jars and essentia type for each jar location. For example: ejar["tilejar_102"]="ordo" | |
| 9 | local ejar = {}
| |
| 10 | ||
| 11 | -- Temp/testing var | |
| 12 | local tmp | |
| 13 | ||
| 14 | local jars = peripheral.getNames() | |
| 15 | local m = peripheral.wrap("monitor_0")
| |
| 16 | local monCoord = {}
| |
| 17 | local currEssentia | |
| 18 | local fillAmt = 0 | |
| 19 | local rowsActive = true | |
| 20 | ||
| 21 | function sortEss(t) | |
| 22 | local keys = {}
| |
| 23 | for k in pairs(t) do keys[#keys+1] = k end | |
| 24 | table.sort(keys) | |
| 25 | ||
| 26 | local i = 0 | |
| 27 | return function() | |
| 28 | - | if peripheral.getType(j) == "tilejar" then |
| 28 | + | |
| 29 | - | --print(peripheral.call(j, "listMethods")) |
| 29 | + | |
| 30 | - | pw = peripheral.wrap(j) |
| 30 | + | |
| 31 | - | asp = pw.getEssentiaType('front')
|
| 31 | + | |
| 32 | - | --asp = peripheral.call(j, getEssentiaType("front"))
|
| 32 | + | |
| 33 | - | --print(asp) |
| 33 | + | |
| 34 | - | countasp = pw.getEssentiaAmount('front')
|
| 34 | + | |
| 35 | - | if countasp > 0 then |
| 35 | + | |
| 36 | - | essentia[asp] = math.floor(countasp) |
| 36 | + | -- This function will do the initial scan all of the jars and store the values in the array essentia & ejar |
| 37 | - | end |
| 37 | + | function initScan() |
| 38 | - | -- print(countasp) |
| 38 | + | print("Starting inital scan")
|
| 39 | - | -- print(asp..":"..countasp) |
| 39 | + | |
| 40 | - | -- print(peripheral.getType(j)) |
| 40 | + | if peripheral.getType(j) == "tilejar" then |
| 41 | pw = peripheral.wrap(j) | |
| 42 | asp = pw.getEssentiaType('front')
| |
| 43 | ejar[j] = asp | |
| 44 | --print(" "..j.." = "..ejar[j])
| |
| 45 | countasp = pw.getEssentiaAmount('front')
| |
| 46 | if countasp > 0 then | |
| 47 | essentia[asp] = math.floor(countasp) | |
| 48 | else | |
| 49 | essentia[asp] = 0 | |
| 50 | - | -- for a = 1,17 do |
| 50 | + | |
| 51 | end | |
| 52 | end | |
| 53 | --print(" tilejar_178 = "..ejar["tilejar_178"])
| |
| 54 | - | if j>=40 then m.setTextColor(colors.green) end |
| 54 | + | |
| 55 | ||
| 56 | ||
| 57 | -- This function will scan all of the jars and store the value in the array essentia | |
| 58 | function scanEssentia() | |
| 59 | print("Starting scan function")
| |
| 60 | - | -- print(j) |
| 60 | + | --print(" tilejar_183 = "..ejar["tilejar_183"])
|
| 61 | for i,j in pairs(ejar) do | |
| 62 | --print(" "..i.." = "..j)
| |
| 63 | pw = peripheral.wrap(i) | |
| 64 | --asp = pw.getEssentiaType('front')
| |
| 65 | countasp = pw.getEssentiaAmount('front')
| |
| 66 | --print(" "..j.." = "..countasp)
| |
| 67 | if countasp > 0 then | |
| 68 | essentia[j] = math.floor(countasp) | |
| 69 | else | |
| 70 | - | -- end |
| 70 | + | essentia[j] = 0 |
| 71 | end | |
| 72 | end | |
| 73 | end | |
| 74 | ||
| 75 | function printEssentia() | |
| 76 | m.setTextColor(colors.white) | |
| 77 | local x = 1 | |
| 78 | local y = 1 | |
| 79 | monCoord[x] = {}
| |
| 80 | for i,j in sortEss(essentia) do | |
| 81 | if j<=20 then m.setTextColor(colors.red) end | |
| 82 | if j<40 and j>20 then m.setTextColor(colors.yellow) end | |
| 83 | if j>=40 and j<64 then m.setTextColor(colors.lightBlue) end | |
| 84 | if j==64 then m.setTextColor(colors.green) end | |
| 85 | ||
| 86 | m.setCursorPos(x,y) | |
| 87 | m.write(i) | |
| 88 | m.setCursorPos(x+14,y) | |
| 89 | m.write(tostring(j)) | |
| 90 | monCoord[x][y] = i | |
| 91 | if y < 17 then | |
| 92 | y = y+1 | |
| 93 | else | |
| 94 | y = 1 | |
| 95 | x = x+17 | |
| 96 | monCoord[x] = {}
| |
| 97 | end | |
| 98 | end | |
| 99 | m.setTextColor(colors.white) | |
| 100 | end | |
| 101 | ||
| 102 | function getClick() | |
| 103 | local event,side,x,y = os.pullEvent() | |
| 104 | if event=="monitor_touch" then | |
| 105 | if button.checkxy(x,y) then | |
| 106 | print("button")
| |
| 107 | else | |
| 108 | if rowsActive then | |
| 109 | fillAmt = 0 | |
| 110 | - | rowsActive = true |
| 110 | + | |
| 111 | print(monCoord[x-(x%17)+1][y]) | |
| 112 | - | button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
|
| 112 | + | |
| 113 | if currEssentia ~= nil then | |
| 114 | if essentia[currEssentia] < 64 then | |
| 115 | fillTable2() | |
| 116 | else | |
| 117 | m.clear() | |
| 118 | button.label(1,10, currEssentia.." is already full. Please choose another.") | |
| 119 | sleep(3) | |
| 120 | refresh() | |
| 121 | end | |
| 122 | end | |
| 123 | end | |
| 124 | end | |
| 125 | end | |
| 126 | end | |
| 127 | ||
| 128 | function refresh() | |
| 129 | button.flash("Refresh")
| |
| 130 | m.clear() | |
| 131 | scanEssentia() | |
| 132 | printEssentia() | |
| 133 | print("Refreshed")
| |
| 134 | button.screen() | |
| 135 | end | |
| 136 | ||
| 137 | -- This function will fill all empty jars to 64 | |
| 138 | function fillAll() | |
| 139 | m.clear() | |
| 140 | button.label(7, 8, " Now filling all jars") | |
| 141 | button.label(7, 10, "Wait for aspects to finish cooking......") | |
| 142 | button.label(7, 12, "Don't forget to refresh the screen after") | |
| 143 | button.label(7, 13, "the golems are done moving the essentia.") | |
| 144 | local essData = {}
| |
| 145 | button.flash("Fill All")
| |
| 146 | for i,j in ipairs(jars) do | |
| 147 | if peripheral.getType(j) == "tilejar" then | |
| 148 | pw = peripheral.wrap(j) | |
| 149 | asp = ejar[j] | |
| 150 | countasp = pw.getEssentiaAmount('front')
| |
| 151 | if countasp > 0 then | |
| 152 | essentia[asp] = math.floor(countasp) | |
| 153 | else | |
| 154 | essentia[asp] = 0 | |
| 155 | end | |
| 156 | if essentia[asp] >= 64 then | |
| 157 | print(asp.." is full") | |
| 158 | else | |
| 159 | print(asp.." needs "..64-essentia[asp]) | |
| 160 | essData[1] = asp | |
| 161 | essData[2] = 64-essentia[asp] | |
| 162 | local sendData = "" | |
| 163 | sendData = textutils.serialize(essData) | |
| 164 | print("turtleID = "..turtleID..", sendData = "..sendData)
| |
| 165 | rednet.send(turtleID, sendData) | |
| 166 | rednet.receive() | |
| 167 | end | |
| 168 | end | |
| 169 | end | |
| 170 | m.clear() | |
| 171 | fillTable() | |
| 172 | printEssentia() | |
| 173 | refresh() | |
| 174 | end | |
| 175 | ||
| 176 | function fillTable() | |
| 177 | rowsActive = true | |
| 178 | button.clearTable() | |
| 179 | button.setTable("Fill All", fillAll, "", 5, 23, 19, 19)
| |
| 180 | button.setTable("Refresh", refresh, "", 27, 46, 19, 19)
| |
| 181 | button.screen() | |
| 182 | end | |
| 183 | ||
| 184 | function addEss(num) | |
| 185 | fillAmt = fillAmt + num | |
| 186 | if fillAmt < 0 then fillAmt = 0 end | |
| 187 | if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end | |
| 188 | m.clear() | |
| 189 | fillTable2() | |
| 190 | end | |
| 191 | ||
| 192 | function fillEss() | |
| 193 | local essData = {}
| |
| 194 | essData[1] = currEssentia | |
| 195 | essData[2] = fillAmt | |
| 196 | local sendData = "" | |
| 197 | sendData = textutils.serialize(essData) | |
| 198 | print("turtleID = "..turtleID..", sendData = "..sendData)
| |
| 199 | rednet.send(turtleID, sendData) | |
| 200 | m.clear() | |
| 201 | button.label(7, 10, "Waiting for aspects to finish cooking....") | |
| 202 | button.label(7, 12, "Don't forget to refresh the screen after") | |
| 203 | button.label(7, 13, "the golem is done moving the essentia.") | |
| 204 | rednet.receive() | |
| 205 | m.clear() | |
| 206 | fillTable() | |
| 207 | printEssentia() | |
| 208 | --refresh() | |
| 209 | end | |
| 210 | ||
| 211 | function cancel() | |
| 212 | m.clear() | |
| 213 | fillTable() | |
| 214 | refresh() | |
| 215 | end | |
| 216 | ||
| 217 | function fillTable2() | |
| 218 | rowsActive = false | |
| 219 | button.clearTable() | |
| 220 | m.clear() | |
| 221 | button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia]) | |
| 222 | button.setTable("+1", addEss, 1, 8, 18, 6,6)
| |
| 223 | button.setTable("+5", addEss, 5, 20, 30, 6, 6)
| |
| 224 | button.setTable("+10", addEss, 10, 32, 42, 6, 6)
| |
| 225 | button.setTable("-1", addEss, -1, 8, 18, 8, 8)
| |
| 226 | button.setTable("-5", addEss, -5, 20, 30, 8, 8)
| |
| 227 | button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
| |
| 228 | button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
| |
| 229 | button.setTable("Execute Fill Request", fillEss, "", 8, 42, 16, 18)
| |
| 230 | button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
| |
| 231 | button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.") | |
| 232 | button.screen() | |
| 233 | end | |
| 234 | ||
| 235 | fillTable() | |
| 236 | initScan() | |
| 237 | refresh() | |
| 238 | while true do getClick() end |