Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- number of seconds before rebooting the machine, use -1 to disable
- local timeToReboot = 300
- --time in seconds between updates
- local sleepTime = 0.5
- -- the itemid of item to charge
- local chargeItemID = 30473
- sorter = peripheral.wrap("right")
- function SecondsToClock(sSeconds)
- local nSeconds = tonumber(sSeconds)
- if nSeconds == 0 then
- return "00:00:00";
- else
- nHours = string.format("%02d", math.floor(nSeconds/3600));
- nMins = string.format("%02d", math.floor(nSeconds/60 - (nHours*60)));
- nSecs = string.format("%02d", math.floor(nSeconds - nHours*3600 - nMins *60));
- return nHours..":"..nMins..":"..nSecs
- end
- end
- local w,h = term.getSize()
- function printStatus()
- term.clear()
- local clockTime = "Time: "..SecondsToClock(seconds)
- term.setCursorPos(w - #clockTime+1, 1)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(clockTime)
- if timeToReboot > 0 then
- local rebootDisplay = "Reboot in: "..string.format("%d",(timeToReboot - seconds))
- term.setCursorPos(w - #rebootDisplay+1, 2)
- term.write(rebootDisplay)
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- --[[ Original code by NeverCast, revised for v3.0 by lost_RD
- This should be loaded like a typical api
- Feel free to name it what you like
- This paste created for http://ftbwiki.org/Interactive_Sorter
- --]]
- local directions = { [0]=0,[1]=1,[2]=2,[3]=3,[4]=4,[5]=5,["down"] = 0, ["up"] = 1, ["-Z"] = 2, ["+Z"] = 3, ["-X"] = 4, ["+X"] = 5, ["+Y"] = 1, ["-Y"] = 0}
- directions.south = directions["+Z"]
- directions.east = directions["+X"]
- directions.north = directions["-Z"]
- directions.west = directions["-X"]
- -- Gets the Unique ID based on the ID and Meta
- function getUUID(id, meta)
- uuid = id + meta * 32768
- return uuid
- end
- -- Get a stack table from a single uuid and amount
- -- Valid for version 3.0
- function getID(uuid)
- id = uuid
- meta = 0
- if uuid > 32768 then
- meta = uuid%32768
- id = id - (meta * 32768)
- end
- end
- function getStack(uuid, c)
- local stack = {}
- stack.id = uuid
- stack.meta = 0
- if uuid > 32768 then
- stack.meta = uuid%32768
- stack.id = stack.id - (stack.meta * 32768)
- end
- stack.count = c
- stack.uuid = uuid
- return stack
- end
- -- Get stacks from an Interactive Sorter
- -- direction : the direction of the Interactive Sorter Peripheral
- -- invDirection: the direction of the inventory from the peripheral
- -- valid options for invDirection are 0,1,2,3,4,5 ( original values),
- -- north, south, east, west, up, down, and the +/-X,Y,Z strings.
- -- (see directions variable)
- function getStacks(direction, invDirection)
- if not peripheral.isPresent(direction) then
- return false, "No Peripheral"
- end
- if peripheral.getType(direction) ~= "interactiveSorter" then
- return false, "Not a sorter"
- end
- local stacks = {}
- for uuid,count in pairs(peripheral.call(direction, "list", directions[invDirection])) do
- table.insert(stacks, getStack(uuid, count))
- end
- return true, stacks
- end
- local isRunning = true
- local reboot = false
- local charging = false
- while isRunning do
- printStatus()
- local isSorter, stacks = getStacks("right", "up")
- if not charging and isSorter then
- for key, value in pairs(stacks) do
- if not charging and stack.id == chargeItemID then
- local stack = stacks[key]
- sorter.extract(directions.up, stack.uuid, directions.down, 1)
- term.setCursorPos(1,1)
- term.write("Charging...")
- sleep(1)
- charging = true
- end
- end
- else if charging and isSorter then
- isSorter, stacks = getStacks("right", "down")
- for key, value in pairs(stacks) do
- if stack.id == chargeItemID and stack.meta == 0 then
- local stack = stacks[key]
- sorter.extract(directions.down, stack.uuid, directions.up, 1)
- term.setCursorPos(1,1)
- term.write("Done charging, Moving item up")
- sleep(1)
- charging = false
- end
- end
- end
- if not charging and timeToReboot > 0 and seconds >= timeToReboot then
- term.clear()
- term.setCursorPos(1,1)
- term.write("Rebooting...")
- reboot = true
- isRunning = false
- sleep(2)
- else
- seconds = seconds + sleepTime
- sleep(sleepTime)
- end
- end
- if reboot then os.reboot() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement