Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local EMC_PER_ITEM_IN = 28
- local EMC_PER_ITEM_OUT = 256
- -- Suck, craft, then drop
- local slots = {1, 2, 3, 5, 6, 7, 9, 10, 11}
- local cycle = 0
- local mx, my = term.getSize()
- local paused = false
- local function writeOnLine(y, thing)
- if y > my then
- term.scroll(1)
- y = my
- end
- local rep = string.rep(' ', mx)
- term.setCursorPos(1, y)
- io.write(rep)
- term.setCursorPos(1, y)
- io.write(thing)
- end
- local function grabItems(count)
- local _, cy = term.getCursorPos()
- local grabbed = 0
- local slot = turtle.getSelectedSlot()
- while grabbed < count do
- writeOnLine(cy, string.format("Grabbing items: %d / %d", grabbed, count))
- turtle.suck(count - grabbed)
- grabbed = turtle.getItemCount(slot)
- end
- print()
- print("Done.")
- end
- local function eachSlot(func)
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- func()
- end
- end
- end
- local function main()
- local emcGenerated = 0
- local itemsGenerated = 0
- while true do
- print(string.format("Starting cycle %d.", cycle))
- -- Get 64 items in each slot
- for i = 1, 9 do
- print(string.format("Grabbing slot %d (%d).", i, slots[i]))
- turtle.select(slots[i])
- grabItems(64)
- end
- -- craft 64 items
- print("Crafting.")
- turtle.craft(64)
- -- drop everything
- print("Dropping back in")
- eachSlot(turtle.drop)
- print()
- print("Done.")
- local genned = (64 * EMC_PER_ITEM_OUT) - (64 * EMC_PER_ITEM_IN * 9)
- local items = math.floor(genned / EMC_PER_ITEM_IN + 0.5)
- print(string.format("Generated %d EMC.", genned))
- emcGenerated = emcGenerated + genned
- print(string.format("Current total EMC generated: %d", emcGenerated))
- print(string.format("Current total base items generated: %d", emcGenerated / EMC_PER_ITEM_IN))
- -- grab the amount of items we collected, stick them in the collector above us.
- print(string.format("Grabbing %d items and placing them into the extras chest...", items))
- grabItems(items)
- print("Dropping into inv below.")
- eachSlot(turtle.dropDown)
- -- if paused, wait until unpaused.
- if paused then
- print("Paused. Waiting for unpause signal (spacebar).")
- os.pullEvent("unpause")
- print("Unpaused. Resuming.")
- end
- print("Waiting 1 second.")
- end
- end
- local function pauser()
- while true do
- local ev = {os.pullEvent("key")}
- if ev[2] == keys.space then
- if paused then
- os.queueEvent("unpause")
- print()
- print("===========================")
- print("Turtle set to unpause.")
- print("===========================")
- print()
- else
- print()
- print("===========================")
- print("At the end of this cycle, turtle will pause.")
- print("===========================")
- print()
- end
- paused = not paused
- end
- end
- end
- parallel.waitForAny(main, pauser)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement