Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --mana
- local target = 12
- --comparator
- local compSide = "front"
- ---cakeChest
- local chestSide = "back"
- local reverse = "south"
- --turtle
- local buffer = 16
- local cakeSlot = 1
- local chest = peripheral.wrap(chestSide)
- function lowCake()
- return turtle.getItemCount(cakeSlot) < (buffer/2)
- end
- function round(n)
- return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
- end
- function refillCake()
- if lowCake() then
- local as = chest.getAllStacks()
- for i=1,#as do
- if as[i].name == "cake" and lowCake() then
- chest.pushItem(reverse,i,(buffer-turtle.getItemCount(cakeSlot)),cakeSlot)
- end
- end
- end
- end
- function getLevel()
- local lvl = rs.getAnalogInput(compSide)
- print("Mana level is "..round(lvl*100/15).."%")
- return lvl
- end
- refillCake()
- while true do
- while getLevel() < target do
- print("RECHARGING!")
- if not turtle.detectUp() then
- turtle.select(cakeSlot)
- if turtle.placeUp() then
- refillCake()
- else
- print("Error placing cake!")
- end
- else
- print("Previous cake still present!")
- end
- sleep(8)
- end
- sleep(8)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement