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
- function initializeTop()
- words(header, "c", 1)
- term.setCursorPos(1, 2)
- for i = 1, w do
- term.write("-")
- end
- end
- header = "RecipeHub"
- local action = nil
- local finished = false
- local ended = false
- local initializedMain = false
- while not ended do ------======MAIN======------
- while not initializedMain do
- resetTxtBak()
- term.clear()
- header = "RecipeHub"
- 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)
- initializedMain = true
- end
- 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 ------======ADD======------
- 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)
- words("Back", "r", 1, colors.white, colors.black)
- 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(w - 3, 1, w, 1) then
- words("Back", "r", 1, colors.white, colors.red)
- sleep(.2)
- initializedMain = false
- finished = true
- else
- words("Back", "r", 1, colors.white, colors.black)
- 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 = nil
- 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
- words("New Recipe", "l + 2", h - 1, colors.yellow, colors.black)
- sleep(.2)
- subfinished = true
- end
- if clickCheck(15, h - 1, 23, h - 1) then
- words("New Stage", "c", h - 1, colors.orange, colors.black)
- sleep(.2)
- subfinished = true
- stage = stage + 1
- end
- if clickCheck(w - 9, h - 1, w - 2, h - 1) then
- words("Finished", "r - 2", h - 1, colors.red, colors.black)
- sleep(.2)
- initializedMain = false
- 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)
- words("Back", "r", 1, colors.white, colors.black)
- 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
- elseif action == "use" then ------======USE======------
- action = nil
- local recipelength = 0
- local activeitems = 0
- header = "Use a Recipe"
- local active = nil
- initializeTop()
- words("Back", "r", 1, colors.white, colors.black)
- os.loadAPI("recipes/list")
- for i = 1, #list.recipeslist do
- words(list.recipeslist[i][13], "l", i + 2, colors.white, colors.black)
- end
- while not finished do
- clicked = {os.pullEvent("mouse_click")}
- if active and clickCheck(w - 5, active + 2, w, active + 2) then
- words(list.recipeslist[active][12] .. "ing...", "r", active + 2, colors.cyan, colors.white)
- sleep(.2)
- if list.recipeslist[active][12] == "Craft" then ------======CRAFTING======------
- shell.run("go left 2")
- activeitems = 0
- turtle.select(13)
- while activeitems ~= recipelength - 2 and turtle.suckUp() do
- data = turtle.getItemDetail(13)
- recipelength = 0
- for i, v in pairs(list.recipeslist[active]) do
- recipelength = recipelength + 1
- if data.name == v then
- activeitems = activeitems + 1
- turtle.transferTo(i, 1)
- end
- end
- turtle.drop()
- end
- if activeitems == recipelength - 2 then
- turtle.select(4)
- turtle.craft(1)
- end
- turtle.select(1)
- while turtle.suck() do
- turtle.dropUp()
- end
- for i = 1, 16 do
- turtle.select(i)
- turtle.dropUp()
- end
- shell.run("go left 2")
- elseif list.recipeslist[active][12] == "Smelt" then ------======SMELTING======------
- shell.run("go left 2")
- activeitems = 0
- turtle.select(13)
- while activeitems ~= 2 and turtle.suckUp() do
- data = turtle.getItemDetail(13)
- recipelength = 0
- for i, v in pairs(list.recipeslist[active]) do
- recipelength = recipelength + 1
- if data.name == v then
- activeitems = activeitems + 1
- turtle.transferTo(i, 1)
- end
- if data.name == "minecraft:planks" then
- turtle.transferTo(15)
- end
- end
- turtle.drop()
- end
- if activeitems == 2 then
- turtle.select(13)
- while turtle.suck() do
- turtle.dropUp()
- end
- shell.run("go left forward up forward")
- turtle.select(1)
- turtle.dropDown(1)
- shell.run("go back down 2 forward")
- turtle.select(15)
- turtle.dropUp(1)
- while not turtle.suckUp() do
- sleep(1)
- end
- shell.run("go back up back left")
- for i = 1, 16 do
- turtle.select(i)
- turtle.dropUp()
- end
- end
- end
- end
- active = nil
- for i = 1, #list.recipeslist do
- if clickCheck(1, i + 2, w, i + 2) then
- if list.recipeslist[i][12] == "Craft" then
- term.setBackgroundColor(colors.brown)
- term.setTextColor(colors.white)
- elseif list.recipeslist[i][12] == "Smelt" then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.orange)
- end
- active = i
- words(stringW, 1, i + 2)
- words(list.recipeslist[i][12], "r", i + 2)
- words(list.recipeslist[i][13], "l", i + 2)
- else
- words(stringW, 1, i + 2, colors.white, colors.black)
- words(list.recipeslist[i][13], "l", i + 2)
- end
- end
- if clickCheck(w - 3, 1, w, 1) then
- words("Back", "r", 1, colors.white, colors.red)
- sleep(.2)
- initializedMain = false
- finished = true
- else
- words("Back", "r", 1, colors.white, colors.black)
- 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