SHOW:
|
|
- or go back to the newest paste.
| 1 | local idleStep = 8 | |
| 2 | - | local target = 12 |
| 2 | + | local rechargeStep = 2 |
| 3 | --mana | |
| 4 | local target = 14 --/15 | |
| 5 | --comparator | |
| 6 | local compSide = "front" | |
| 7 | - | local reverse = "south" |
| 7 | + | |
| 8 | local chestSide = "back" | |
| 9 | local reverse = "north" | |
| 10 | --turtle | |
| 11 | local buffer = 16 | |
| 12 | local cakeSlot = 1 | |
| 13 | ||
| 14 | local chest = peripheral.wrap(chestSide) | |
| 15 | print(chest.getInventoryName().." found.") | |
| 16 | ||
| 17 | function lowCake() | |
| 18 | return turtle.getItemCount(cakeSlot) < (buffer/2) | |
| 19 | end | |
| 20 | ||
| 21 | function round(n) | |
| 22 | return n % 1 >= 0.5 and math.ceil(n) or math.floor(n) | |
| 23 | end | |
| 24 | - | local as = chest.getAllStacks() |
| 24 | + | |
| 25 | - | for i=1,#as do |
| 25 | + | |
| 26 | - | if as[i].name == "cake" and lowCake() then |
| 26 | + | |
| 27 | - | chest.pushItem(reverse,i,(buffer-turtle.getItemCount(cakeSlot)),cakeSlot) |
| 27 | + | print("Cake level is low(inf. "..(buffer/2)..")")
|
| 28 | local as = chest.getAllStacks(false) | |
| 29 | for i,slot in pairs(as) do | |
| 30 | if slot ~= nil and slot.name == "cake" and lowCake() then | |
| 31 | print(chest.pushItem(reverse,i,(buffer-turtle.getItemCount(cakeSlot)),cakeSlot).." cakes retrieved from slot "..i..".") | |
| 32 | end | |
| 33 | end | |
| 34 | end | |
| 35 | end | |
| 36 | ||
| 37 | function getLevel() | |
| 38 | local lvl = rs.getAnalogInput(compSide) | |
| 39 | - | refillCake() |
| 39 | + | |
| 40 | return lvl | |
| 41 | end | |
| 42 | ||
| 43 | while true do | |
| 44 | ||
| 45 | - | if turtle.placeUp() then |
| 45 | + | |
| 46 | - | refillCake() |
| 46 | + | |
| 47 | - | else |
| 47 | + | |
| 48 | turtle.select(cakeSlot) | |
| 49 | refillCake() | |
| 50 | if not turtle.placeUp() then | |
| 51 | print("Error placing cake!")
| |
| 52 | end | |
| 53 | - | sleep(8) |
| 53 | + | |
| 54 | print("Previous cake still present!")
| |
| 55 | - | sleep(8) |
| 55 | + | |
| 56 | sleep(rechargeStep) | |
| 57 | end | |
| 58 | ||
| 59 | print("IDLE")
| |
| 60 | sleep(idleStep) | |
| 61 | ||
| 62 | end |