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()
- turtle.select(1)
- if not fs.exists("recipes") then
- fs.makeDir("recipes")
- oTemp = fs.open("recipes/list", "w")
- oTemp.writeLine("recipeslist = {}")
- oTemp.flush()
- oTemp.close()
- end
- if not fs.exists("*crafting") then
- oTemp = fs.open("*crafting", "w")
- oTemp.writeLine("c7cccccc7c")
- oTemp.writeLine("700c00c007")
- oTemp.writeLine("c00c00c00c")
- oTemp.writeLine("cccccccccc")
- oTemp.writeLine("c00c00c00c")
- oTemp.writeLine("c00c00c00c")
- oTemp.writeLine("cccccccccc")
- oTemp.writeLine("c00c00c00c")
- oTemp.writeLine("700c00c007")
- oTemp.writeLine("c7cccccc7c")
- oTemp.flush()
- oTemp.close()
- end
- if not fs.exists("*smelting") then
- oTemp = fs.open("*smelting", "w")
- oTemp.writeLine("7777777777")
- oTemp.writeLine("77ffffff77")
- oTemp.writeLine("7ffffffff7")
- oTemp.writeLine("7ffffffff7")
- oTemp.writeLine("7777777777")
- oTemp.writeLine("8888888888")
- oTemp.writeLine("88ee4e1e88")
- oTemp.writeLine("81e41ee4e8")
- oTemp.writeLine("8ee1e4e148")
- oTemp.writeLine("8888888888")
- oTemp.flush()
- oTemp.close()
- end
- local craftImg = paintutils.loadImage("*crafting")
- local smeltImg = paintutils.loadImage("*smelting")
- local stringW = ""
- for i = 1, w do
- stringW = stringW .. " "
- end
- 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) and 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 = "RecipeHub"
- function initializeTop()
- words(header, "c", 1)
- term.setCursorPos(1, 2)
- for i = 1, w do
- term.write("-")
- end
- end
- initializeTop()
- paintutils.drawImage(craftImg, 1, 1)
- paintutils.drawImage(smeltImg, w - 9, 1)
- resetTxtBak()
- words("Add a Recipe", "l + 3", h - 1)
- words("Use a Recipe", "r - 3", h - 1)
- words("Begin", "c", h - 2)
- local action = nil
- local finished = false
- local ended = false
- while not ended do
- clicked = {os.pullEvent("mouse_click")}
- if clickCheck(4, h - 1, 15, h - 1) then
- words("Add a Recipe", "l + 3", h - 1, colors.white, colors.blue)
- words("Use a Recipe", "r - 3", h - 1, colors.white, colors.black)
- action = "add"
- end
- if clickCheck(w - 14, h - 1, w - 3, h - 1) then
- words("Add a Recipe", "l + 3", h - 1, colors.white, colors.black)
- words("Use a Recipe", "r - 3", h - 1, colors.white, colors.blue)
- action = "use"
- end
- if clickCheck(18, h - 2, 22, h - 2) then
- if action then
- words("Begin", "c", h - 2, colors.green, colors.black)
- sleep(.1)
- local finished = false
- local subfinished = false
- local stage = 1
- local change = 0
- local iName = nil
- 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("Name: ", "l", 7)
- words("Record", "l", 9)
- 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, 12, 7) then
- words(stringW, 1, 7, colors.yellow, colors.lightGray)
- words("Name:", 1, 7)
- term.setCursorPos(7, 7)
- iName = read()
- words(stringW, 1, 7, colors.white, colors.black)
- words("Name:", 1, 7)
- words(iName, "l + 6", 7)
- end
- if clickCheck(1, 9, 6, 9) then
- words("Record", "l", 9, colors.green, colors.black)
- if action and iName then
- change = 0
- for i = 1, 9 do
- turtle.select(i + change)
- data = turtle.getItemDetail(i + change)
- if data then
- newRecipe[i + change] = 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.writeLine("recipeslist[" .. num .. "][12] = \"" .. action .. "\"")
- oTemp.writeLine("recipeslist[" .. num .. "][13] = \"" .. iName .. "\"")
- oTemp.flush()
- oTemp.close()
- shell.run("delete list")
- shell.run("copy temp list")
- shell.run("delete temp")
- shell.run("cd /")
- words("Record", "l", 9, colors.white, colors.black)
- words("New Recipe", "l + 2", h - 1, colors.white, colors.black)
- words("New Stage", "c", h - 1)
- words("Finished", "r - 2", h - 1)
- subfinished = false
- while not subfinished do
- clicked = {os.pullEvent("mouse_click")}
- if clickCheck(3, h - 1, 12, h - 1) then
- subfinished = true
- end
- if clickCheck(15, h - 1, 23, h - 1) then
- subfinished = true
- stage = stage + 1
- end
- if clickCheck(w - 7, h - 1, w, h - 1) then
- subfinished = true
- finished = true
- end
- end
- resetTxtBak()
- term.clear()
- action = nil
- header = "Add a Recipe"
- initializeTop()
- words("Stage " .. tostring(stage), "l", 3)
- words("Craft", "l + 5", 5)
- words("Smelt", "r - 5", 5)
- words("Name: ", "l", 7)
- words("Record", "l", 9)
- else
- for i = 1, 2 do
- words("Record", 1, 9, colors.red, colors.black)
- sleep(.1)
- words("Record", 1, 9, colors.white, colors.black)
- sleep(.1)
- end
- end
- end
- end
- end
- else
- for i = 1, 2 do
- words("Begin", "c", h - 2, colors.red, colors.black)
- sleep(.1)
- words("Begin", "c", h - 2, colors.white, colors.black)
- sleep(.1)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement