SHOW:
|
|
- or go back to the newest paste.
| 1 | rednet.open("left")
| |
| 2 | os.loadAPI("button")
| |
| 3 | local turtleID = 18 | |
| 4 | local essentia = {}
| |
| 5 | local jars = peripheral.getNames() | |
| 6 | local m = peripheral.wrap("top")
| |
| 7 | local monCoord = {}
| |
| 8 | local currEssentia | |
| 9 | local fillAmt = 0 | |
| 10 | local rowsActive = true | |
| 11 | ||
| 12 | function sortEss(t) | |
| 13 | local keys = {}
| |
| 14 | for k in pairs(t) do keys[#keys+1] = k end | |
| 15 | table.sort(keys) | |
| 16 | ||
| 17 | local i = 0 | |
| 18 | return function() | |
| 19 | i = i+1 | |
| 20 | if keys[i] then | |
| 21 | return keys[i], t[keys[i]] | |
| 22 | end | |
| 23 | end | |
| 24 | end | |
| 25 | ||
| 26 | function scanEssentia() | |
| 27 | for i,j in ipairs(jars) do | |
| 28 | if peripheral.getType(j) == "tilejar" then | |
| 29 | --print(peripheral.call(j, "listMethods")) | |
| 30 | pw = peripheral.wrap(j) | |
| 31 | asp = pw.getEssentiaType('front')
| |
| 32 | --asp = peripheral.call(j, getEssentiaType("front"))
| |
| 33 | --print(asp) | |
| 34 | countasp = pw.getEssentiaAmount('front')
| |
| 35 | if countasp > 0 then | |
| 36 | essentia[asp] = math.floor(countasp) | |
| 37 | end | |
| 38 | -- print(countasp) | |
| 39 | print(asp..":"..countasp) | |
| 40 | -- print(peripheral.getType(j)) | |
| 41 | end | |
| 42 | end | |
| 43 | end | |
| 44 | ||
| 45 | function printEssentia() | |
| 46 | m.setTextColor(colors.white) | |
| 47 | local x = 1 | |
| 48 | local y = 1 | |
| 49 | monCoord[x] = {}
| |
| 50 | -- for a = 1,17 do | |
| 51 | for i,j in sortEss(essentia) do | |
| 52 | if j<=20 then m.setTextColor(colors.red) end | |
| 53 | if j<40 and j>20 then m.setTextColor(colors.yellow) end | |
| 54 | if j>=40 then m.setTextColor(colors.green) end | |
| 55 | ||
| 56 | m.setCursorPos(x,y) | |
| 57 | m.write(i) | |
| 58 | m.setCursorPos(x+14,y) | |
| 59 | m.write(tostring(j)) | |
| 60 | -- print(j) | |
| 61 | monCoord[x][y] = i | |
| 62 | if y < 17 then | |
| 63 | y = y+1 | |
| 64 | else | |
| 65 | y = 1 | |
| 66 | x = x+17 | |
| 67 | monCoord[x] = {}
| |
| 68 | end | |
| 69 | end | |
| 70 | -- end | |
| 71 | m.setTextColor(colors.white) | |
| 72 | end | |
| 73 | ||
| 74 | function getClick() | |
| 75 | local event,side,x,y = os.pullEvent() | |
| 76 | if event=="monitor_touch" then | |
| 77 | if button.checkxy(x,y) then | |
| 78 | print("button")
| |
| 79 | else | |
| 80 | if rowsActive then | |
| 81 | fillAmt = 0 | |
| 82 | print(x..":"..x-(x%17)+1) | |
| 83 | print(monCoord[x-(x%17)+1][y]) | |
| 84 | currEssentia = monCoord[x-(x%17)+1][y] | |
| 85 | if currEssentia ~= nil then | |
| 86 | if essentia[currEssentia] < 64 then | |
| 87 | fillTable2() | |
| 88 | else | |
| 89 | m.clear() | |
| 90 | button.label(1,10, currEssentia.." is already full. Please choose another.") | |
| 91 | sleep(3) | |
| 92 | refresh() | |
| 93 | end | |
| 94 | end | |
| 95 | end | |
| 96 | end | |
| 97 | end | |
| 98 | end | |
| 99 | ||
| 100 | function refresh() | |
| 101 | button.flash("Refresh")
| |
| 102 | m.clear() | |
| 103 | scanEssentia() | |
| 104 | printEssentia() | |
| 105 | print("Refreshed")
| |
| 106 | button.screen() | |
| 107 | end | |
| 108 | ||
| 109 | function fillTable() | |
| 110 | rowsActive = true | |
| 111 | button.clearTable() | |
| 112 | button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
| |
| 113 | button.screen() | |
| 114 | end | |
| 115 | ||
| 116 | function addEss(num) | |
| 117 | fillAmt = fillAmt + num | |
| 118 | if fillAmt < 0 then fillAmt = 0 end | |
| 119 | if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end | |
| 120 | m.clear() | |
| 121 | fillTable2() | |
| 122 | end | |
| 123 | ||
| 124 | function fillEss() | |
| 125 | local essData = {}
| |
| 126 | essData[1] = currEssentia | |
| 127 | essData[2] = fillAmt | |
| 128 | local sendData = "" | |
| 129 | sendData = textutils.serialize(essData) | |
| 130 | rednet.send(turtleID, sendData) | |
| 131 | m.clear() | |
| 132 | button.label(7, 10, "Waiting for aspects to finish cooking....") | |
| 133 | button.label(7, 12, "Don't forget to refresh the screen after") | |
| 134 | button.label(7, 13, "the golem is done moving the essentia.") | |
| 135 | rednet.receive() | |
| 136 | m.clear() | |
| 137 | fillTable() | |
| 138 | refresh() | |
| 139 | end | |
| 140 | ||
| 141 | function cancel() | |
| 142 | m.clear() | |
| 143 | fillTable() | |
| 144 | refresh() | |
| 145 | end | |
| 146 | ||
| 147 | function fillTable2() | |
| 148 | rowsActive = false | |
| 149 | button.clearTable() | |
| 150 | m.clear() | |
| 151 | button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia]) | |
| 152 | button.setTable("+1", addEss, 1, 8, 18, 6,6)
| |
| 153 | button.setTable("+5", addEss, 5, 20, 30, 6, 6)
| |
| 154 | button.setTable("+10", addEss, 10, 32, 42, 6, 6)
| |
| 155 | button.setTable("-1", addEss, -1, 8, 18, 8, 8)
| |
| 156 | button.setTable("-5", addEss, -5, 20, 30, 8, 8)
| |
| 157 | button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
| |
| 158 | button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
| |
| 159 | button.setTable("Execute Fill Request", fillEss, "", 8, 42, 16, 18)
| |
| 160 | button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
| |
| 161 | button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.") | |
| 162 | button.screen() | |
| 163 | end | |
| 164 | ||
| 165 | fillTable() | |
| 166 | refresh() | |
| 167 | while true do getClick() end |