Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Author: TheOriginalBIT
- Version: 1.0
- Created: 14 Dec 2012
- ]]--
- -----------------------------------
- ----- UPDATE SERVER VARIABLES -----
- -----------------------------------
- creator = "TheOriginalBIT"
- version = 1.0
- progName = "Flint Maker"
- identifier = ("com.TOBIT."..progName)
- forSys = Turtle
- -----------------------------------
- ------------- UI CODE -------------
- ------ CODE FROM Cookiebal's ------
- ------ Cookie System program ------
- -----------------------------------
- sizeX, sizeY = term.getSize()
- local function formatTime(nTime)
- local nHour = math.floor(nTime)
- local nMinute = math.floor( (nTime - nHour) * 60 )
- return string.format("%02d:%02d", nHour, nMinute)
- end
- local function drawTime(x, y)
- sX, sY = term.getCursorPos()
- if x == nil or y == nil then return end
- local nTime = os.time()
- local currTime = formatTime(nTime)
- term.setCursorPos(x,y)
- write(currTime)
- term.setCursorPos(sX, sY)
- end
- local function drawBorder(x1, y1, x2, y2, filled)
- for y = y1, y2 do
- for x = x1, x2 do
- term.setCursorPos(x, y)
- if (x == x1 and y == y1) or (x == x1 and y == y2) or (x == x2 and y == y1) or (x == x2 and y == y2) then
- write("+")
- elseif x == x1 or x == x2 then
- write("|")
- elseif y == y1 or y == y2 then
- write("-")
- else
- if filled then write(" ") end
- end
- end
- end
- term.setCursorPos(1, y2)
- end
- local function drawTextCenter(text, y)
- if type(text) == "string" then
- term.setCursorPos(sizeX / 2 - (string.len(text) / 2), y)
- write(text)
- elseif type(text) == "table" then
- arr = {}
- arr = text
- for i = 0, table.getn(arr) - 1 do
- term.setCursorPos(sizeX / 2 - (string.len(arr[i + 1]) / 2), y + i)
- write(arr[i + 1])
- end
- end
- end
- -- My own clear screen that makes draws default UI
- local function clearScreen()
- term.clear()
- drawBorder(1, 1, sizeX - 1, 3, false)
- term.setCursorPos(1,1)
- drawTextCenter(string.format("TOBIT %s v%f", progName, version), 2)
- term.setCursorPos(1, 5)
- end
- -----------------------------------
- -------- FLINT MAKER CODE ---------
- -----------------------------------
- currSlot = 1
- showTime = true
- local function clearInvent()
- pcall(sleep, 1)
- clearScreen()
- print("Found Items in inventory...")
- pcall(sleep, 1)
- print("Clearing Inventory for successfull program execution...")
- for i = 1, 9 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- local function countSlotsWithItems()
- local count = 0
- for i = 1, 9 do
- if turtle.getItemCount(i) > 0 then
- count = count + 1
- end
- end
- return count
- end
- local function checkGravelCount()
- x, y = term.getCursorPos()
- while countSlotsWithItems() > 8 do
- term.setCursorPos(x, y)
- print("You gave me too much, I need at least one slot empty for when I make flint.")
- sleep(0.5)
- end
- end
- local function incrementSlot()
- if currSlot ~= 9 then
- currSlot = currSlot + 1
- turtle.select(currSlot)
- return true
- else
- return false
- end
- end
- local function currSlotHasItems()
- return (turtle.getItemCount(currSlot) > 0)
- end
- local function setup()
- clearScreen()
- write("Have you placed gravel in my inventory? ")
- answer = read()
- if string.upper(answer) == "YES" then
- if countSlotsWithItems() == 0 then print("You did not supply me any items") end
- elseif string.upper(answer) == "NO" then
- if countSlotsWithItems() > 0 then clearInvent() end
- else
- print("Unknown response")
- pcall(sleep, 1)
- print("Quitting")
- pcall(sleep, 1)
- return false
- end
- if countSlotsWithItems() == 0 then
- clearScreen()
- print("Please give me some gravel...")
- x, y = term.getCursorPos()
- i = 10
- while i > -1 do
- term.setCursorPos(x, y) -- Overwrite the same line to appear that seconds are changing
- term.clearLine()
- print("Starting in "..i.."...")
- if i == 10 then tx, ty = term.getCursorPos() end
- pcall(sleep, 1)
- i = i - 1
- end
- print()
- if countSlotsWithItems() == 0 then
- clearScreen()
- print("You did not supply me any items")
- print("Quitting")
- return false
- end
- end
- checkGravelCount()
- return true
- end
- local function main()
- while true do
- if currSlotHasItems() then
- turtle.select(currSlot)
- if turtle.place() then -- checks if item is gravel (flint cant be placed)
- turtle.dig()
- else
- incrementSlot()
- end
- else
- clearScreen()
- print("Converted all slots")
- break
- end
- end
- end
- local function updateTime()
- while true do
- drawTime(sizeX - 5, sizeY)
- pcall(sleep, 1)
- end
- end
- function progEntry()
- if turtle then
- if setup() then
- clearScreen()
- print("Converting gravel into flint")
- main()
- end
- else
- clearScreen()
- print("Sorry this program can only run on turtles.")
- end
- pcall(sleep, 2)
- term.clear()
- term.setCursorPos(1,1)
- print(os.version())
- end
- if showTime then
- parallel.waitForAny(progEntry, updateTime)
- else
- progEntry()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement