Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Made by columna1 Please dont claim as your own
- Version 1.1
- Changelog:
- 1.0 release
- 1.1 fixed bug when 3d printing files that were not square (the turtle would not go back to the start pos)
- ]]--
- arg = {...}
- plane = 0
- line = {}
- x = 0
- selecteditem = 1
- mainmenu = true
- menu2d = false
- menu3d = false
- col = {
- w = 1,
- o = 2,
- m = 3,
- b = 4,
- y = 5,
- l = 6,
- p = 7,
- G = 8,
- g = 9,
- c = 10,
- P = 11,
- B = 12,
- n = 13,
- e = 14,
- r = 15,
- d = 16,
- s = 20
- }
- --functions
- function forward()
- forw = true
- while forw do
- if turtle.forward() then
- forw = false
- else
- turtle.dig()
- turtle.attack()
- end
- end
- end
- function placeDown()
- if turtle.getItemCount(selected) > 1 then
- turtle.placeDown()
- else
- nom = true
- print("Enter material")
- while nom do
- sleep(1)
- if turtle.getItemCount(selected) > 1 then
- nom = false
- print("continuing")
- turtle.placeDown()
- end
- end
- end
- end
- function place()
- if turtle.getItemCount(selected) > 1 then
- turtle.place()
- else
- nom = true
- print("Enter material")
- while nom do
- sleep(1)
- if turtle.getItemCount(selected) > 1 then
- nom = false
- print("continuing")
- turtle.place()
- end
- end
- end
- end
- function printer()
- sleep(0.1)
- up = job.readLine()
- for j = 1,tonumber(up) do
- curline = job.readLine()
- if x == 1 then
- curline = curline:reverse()
- end
- for i = 1,#curline do
- line[i] = curline:sub(i,i)
- end
- for i = 1,#line do
- if col[line[i]] == 20 then
- --no selecting
- else
- turtle.select(col[line[i]])
- selected = col[line[i]]
- end
- if plane == 0 then
- if col[line[i]] == 20 then
- --no placing
- else
- placeDown()
- end
- forward()
- else
- if x == 0 then
- if col[line[i]] == 20 then
- --no placing
- else
- place()
- end
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- elseif x == 1 then
- if col[line[i]] == 20 then
- --no placing
- else
- place()
- end
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- end
- end
- end
- if plane == 0 then
- if x == 0 then
- turtle.turnRight()
- forward()
- turtle.turnRight()
- forward()
- x = 1
- elseif x == 1 then
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- forward()
- x = 0
- end
- else
- if x == 0 then
- turtle.down()
- turtle.turnLeft()
- forward()
- turtle.turnRight()
- x = 1
- elseif x == 1 then
- turtle.down()
- turtle.turnRight()
- forward()
- turtle.turnLeft()
- x = 0
- end
- end
- end
- end
- function exit()
- main = false
- term.clear()
- term.setCursorPos(1,1)
- print("Thanks for using Columna1's printer")
- end
- function face()
- plane = 1
- end
- function d3()
- sleep(0.1)
- selecteditem = 1
- menu3d = true
- while menu3d do
- term.clear()
- term.setCursorPos(1,1)
- printmenu(menu3)
- event,key = os.pullEvent("key")
- onkeypress(key,menu3)
- end
- end
- function d2()
- selecteditem = 1
- menu2d = true
- while menu2d do
- term.clear()
- term.setCursorPos(1,1)
- printmenu(menu2)
- event,key = os.pullEvent("key")
- onkeypress(key,menu2)
- end
- end
- function exit3d()
- selecteditem = 1
- menu3d = false
- selecteditem = 1
- end
- function exit2d()
- selecteditem = 1
- menu2d = false
- selecteditem = 1
- end
- function print3d()
- sleep(0.1)
- x = 0
- if tip then
- files = job.readLine()
- job.close()
- for k = 1,tonumber(files) do
- job = fs.open(timp.."_"..k,"r")
- printer()
- if up %2 == 0 then
- turtle.turnLeft()
- for h = 1,up do
- forward()
- end
- turtle.turnRight()
- turtle.up()
- else
- turtle.turnRight()
- for h = 1,up do
- forward()
- end
- turtle.turnLeft()
- for h = 1,#curline-1 do
- forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.up()
- end
- job.close()
- x = 0
- tip = nil
- end
- else
- print("No file Entered")
- sleep(1)
- end
- end
- function print2d()
- x = 0
- if tipe then
- printer()
- tipe = nil
- else
- print("No file entered")
- sleep(1)
- end
- end
- function enter3d()
- print("Enter file prefix")
- timp = read()
- if fs.exists(timp) then
- job = fs.open(timp,"r")
- tip = job.readLine()
- if tip == "3d" then
- -- over with
- else
- print("Not a 3d file")
- sleep(1)
- end
- else
- print("invalid file")
- tip = nil
- sleep(1)
- end
- end
- function enter2d()
- print("Enter filename")
- local temp = read()
- if fs.exists(temp) then
- job = fs.open(temp,"r")
- tipe = job.readLine()
- if tipe == "2d" then
- --another comment to do nothing
- else
- print("Not a 2d file")
- sleep(1)
- end
- else
- print("invalid file")
- tipe = nil
- sleep(1)
- end
- end
- menu = {
- [1] = {text = "2D",handler = d2},
- [2] = {text = "3D",handler = d3},
- [3] = {text = "Exit",handler = exit}
- }
- menu2 = {
- [1] = {text = "Enter filename",handler = enter2d},
- [2] = {text = "Print",handler = print2d},
- [3] = {text = "Plane y",handler = face},
- [4] = {text = "Main menu",handler = exit2d}
- }
- menu3 = {
- [1] = {text = "Enter filename",handler = enter3d},
- [2] = {text = "Print",handler = print3d},
- [3] = {text = "Main menu",handler = exit3d}
- }
- --printmenu
- function printmenu(menu)
- for i = 1,#menu do
- if i == selecteditem then
- print("[[ "..menu[i].text.." ]]")
- else
- print(" "..menu[i].text.." ")
- end
- end
- end
- --handlers
- function onkeypress(key,menu)
- if key == keys.enter then
- onitemselected(menu)
- elseif key == keys.up then
- if selecteditem > 1 then
- selecteditem = selecteditem - 1
- end
- elseif key == keys.down then
- if selecteditem < #menu then
- selecteditem = selecteditem + 1
- end
- end
- end
- function onitemselected(menu)
- menu[selecteditem].handler()
- end
- --main
- function main()
- while main do
- term.clear()
- term.setCursorPos(1,1)
- printmenu(menu)
- event,key = os.pullEvent()
- onkeypress(key,menu)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement