Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local idleStep = 8
- local rechargeStep = 4
- --mana
- local target = 14 --/15
- --comparator
- local compSide = "front"
- ---cakeChest
- local chestSide = "bottom"
- local reverse = "up"
- --turtle
- local buffer = 16
- local cakeSlot = 1
- local chest = peripheral.wrap(chestSide)
- print(chest.getInventoryName().." found.")
- 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
- print("Cake level is low(inf. "..(buffer/2)..")")
- local as = chest.getAllStacks(false)
- for i,slot in pairs(as) do
- if slot ~= nil and slot.name == "cake" and lowCake() then
- print(chest.pushItem(reverse,i,(buffer-turtle.getItemCount(cakeSlot)),cakeSlot).." cakes retrieved from slot "..i..".")
- end
- end
- end
- end
- function getLevel()
- local lvl = rs.getAnalogInput(compSide)
- print("Mana level is "..round(lvl*100/15).."%")
- return lvl
- end
- while true do
- while getLevel() < target do
- print("RECHARGING!")
- if not turtle.detectUp() then
- turtle.select(cakeSlot)
- refillCake()
- if not turtle.placeUp() then
- print("Error placing cake!")
- end
- else
- print("Previous cake still present!")
- end
- sleep(rechargeStep)
- end
- print("IDLE")
- sleep(idleStep)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement