Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- term.setBackgroundColor(colors.black)
- term.clear()
- local offset = 0
- function words(string, x, y, txtcol, bakcol)
- if txtcol then
- term.setTextColor(txtcol)
- end
- if bakcol then
- term.setBackgroundColor(bakcol)
- end
- if not tonumber(x) then
- if string.sub(x, 0, 1) == "l" then
- if x == "l" or x == "left" then
- term.setCursorPos(1, y)
- elseif string.sub(x, 3, 3) == "+" or string.sub(x, 6, 6) == "+" then
- offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 8, 8))
- term.setCursorPos(1 + offset, y)
- end
- elseif string.sub(x, 0, 1) == "c" then
- if x == "center" or x == "c" then
- term.setCursorPos(w / 2 - #string / 2 + 1, y)
- elseif string.sub(x, 3, 3) == "+" or string.sub(x, 8, 8) == "+" then
- offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
- term.setCursorPos(w / 2 - #string / 2 + 1 + offset, y)
- elseif string.sub(x, 3, 3) == "-" or string.sub(x, 8, 8) == "-" then
- offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 10, 10))
- term.setCursorPos(w / 2 - #string / 2 + 1 - offset, y)
- end
- elseif string.sub(x, 0, 1) == "r" then
- if x == "right" or x == "r" then
- term.setCursorPos(w - #string + 1, y)
- elseif string.sub(x, 3, 3) == "-" or string.sub(x, 7, 7) == "-" then
- offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 9, 9))
- term.setCursorPos(w - #string + 1 - offset, y)
- end
- end
- else
- term.setCursorPos(x, y)
- end
- term.write(string)
- end
- function clickCheck(x, y, x2, y2)
- if clicked[3] >= x and clicked[3] <= x2 and clicked[4] >= y and clicked[4] <= y2 then
- return true
- else
- return false
- end
- end
- function resetTxtBak()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- local header = "Recipe Hub"
- function initializeTop()
- words(header, "c", 1)
- term.setCursorPos(1, 2)
- for i = 1, w do
- term.write("-")
- end
- end
- initializeTop()
- words("Add a Recipe", "l + 3", 3)
- words("Use a Recipe", "r - 3", 3)
- words("Begin", "c", 4)
- local action = nil
- local finished = false
- while not finished do
- clicked = {os.pullEvent("mouse_click")}
- if clickCheck(4, 3, 15, 3) then
- words("Add a Recipe", "l + 3", 3, colors.white, colors.blue)
- words("Use a Recipe", "r - 3", 3, colors.white, colors.black)
- action = "add"
- end
- if clickCheck(w - 14, 3, w - 3, 3) then
- words("Add a Recipe", "l + 3", 3, colors.white, colors.black)
- words("Use a Recipe", "r - 3", 3, colors.white, colors.blue)
- action = "use"
- end
- if clickCheck(18, 4, 22, 4) then
- if action then
- words("Begin", "c", 4, colors.green, colors.black)
- sleep(.1)
- finished = true
- else
- for i = 1, 2 do
- words("Begin", "c", 4, colors.red, colors.black)
- sleep(.1)
- words("Begin", "c", 4, colors.white, colors.black)
- sleep(.1)
- end
- end
- end
- end
- local finished = false
- local stage = 1
- local change = 0
- local data = nil
- local newRecipe = {}
- resetTxtBak()
- term.clear()
- if action == "add" then
- action = nil
- header = "Add a Recipe"
- initializeTop()
- words("Stage " .. tostring(stage), "l", 3)
- words("Craft", "l + 5", 5)
- words("Smelt", "r - 5", 5)
- words("Record", "l", 7)
- while not finished do
- clicked = {os.pullEvent("mouse_click")}
- if clickCheck(6, 5, 10, 5) then
- words("Craft", "l + 5", 5, colors.white, colors.brown)
- words("Smelt", "r - 5", 5, colors.white, colors.black)
- action = "craft"
- end
- if clickCheck(w - 10, 5, w - 5, 5) then
- words("Craft", "l + 5", 5, colors.white, colors.black)
- words("Smelt", "r - 5", 5, colors.orange, colors.gray)
- action = "smelt"
- end
- if clickCheck(1, 7, 6, 7) then
- words("Record", "l", 7, colors.green, colors.black)
- if action then
- local change = 0
- for i = 1, 9 do
- turtle.select(i + change)
- data = turtle.getItemDetail(i + change)
- if data then
- newRecipe[i] = tostring(data.name)
- end
- if i == 3 then change = 1 end
- if i == 6 then change = 2 end
- end
- shell.run("cd recipes")
- oTemp = fs.open("recipes/temp", "w")
- for line in io.lines("recipes/list") do
- oTemp.writeLine(line)
- end
- os.loadAPI("recipes/list")
- local num = #list.recipeslist + 1
- oTemp.writeLine("recipeslist[" .. num .. "] = {}")
- for i, v in pairs(newRecipe) do
- oTemp.writeLine("recipeslist[" .. num .. "][" .. i .. "] = " .. v)
- end
- oTemp.flush()
- oTemp.close()
- shell.run("delete list")
- shell.run("copy temp list")
- shell.run("delete temp")
- shell.run("cd /")
- else
- for i = 1, 2 do
- words("Record", 1, 5, colors.red, colors.black)
- sleep(.1)
- words("Record", 1, 5, colors.white, colors.black)
- sleep(.1)
- end
- end
- end
- end
- elseif action == "use" then
- action = nil
- header = "Use a Recipe"
- initializeTop()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement