Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local prt = peripheral.find("printer")
- local args = {...}
- local data = {fs.open("/printer/data.lua","r")}
- if data[1]==nil then print("data.json cannot be opened: "..data[2]) end
- local setup = textutils.unserialise(data[1].readAll())
- data[1].close()
- peripheral.call("minecraft:chest_"..setup.chest_paper,"pushItems","minecraft:hopper_"..setup.printer_paper,1,1)
- while peripheral.call("minecraft:chest_"..(setup.chests_ink_start+math.random(1,15)),"pushItems","minecraft:hopper_"..setup.printer_ink,1,1)==0 do sleep(0.05) end
- local file
- if args[1]==nil then
- file = "/printer/canvas.nfp"
- else
- file = shell.dir()..args[1]
- end
- while not prt.newPage() do sleep(0.05) end
- if not fs.exists(file) then
- local size = {prt.getPageSize()}
- print(size[1],size[2])
- local f = fs.open(file,"w")
- for i=1,size[2] do
- for i=1,size[1] do
- f.write("0")
- end
- f.write("\n")
- end
- f.close()
- end
- prt.endPage()
- shell.run("/printer/rspaint "..file)
- print("Printing 0/15 (0)")
- for i=1,15 do
- local f = fs.open(file,"r")
- write("Waiting for paper")
- while peripheral.call("minecraft:chest_"..setup.printer_output,"pushItems","minecraft:hopper_"..setup.printer_paper,1,1)==0 do
- sleep(0.05)
- write(".")
- end
- print(" Done")
- peripheral.call("minecraft:chest_"..setup.chests_ink_start+i,"pushItems","minecraft:hopper_"..setup.printer_ink,1,1)
- write("Waiting for ink")
- while not prt.newPage() do
- sleep(0.05)
- write(".")
- end
- print(" Done")
- local color_char = colors.toBlit(2^i)
- b = f.read(1)
- while b~=nil do
- if b~="\n" then
- if b==color_char then
- prt.write("\x7f")
- else
- local pos = {prt.getCursorPos()}
- prt.setCursorPos(pos[1]+1,pos[2])
- end
- else
- local pos = {prt.getCursorPos()}
- prt.setCursorPos(1,pos[2]+1)
- end
- b = f.read(1)
- end
- prt.endPage()
- f.close()
- print("Printing "..i.."/15 ("..color_char..")")
- end
- print("Done!")
- term.setTextColor(colors.red)
- if prt.getInkLevel() > 0 then
- print("Uh oh! Something didn't print properly and there's still ink in the printer. Please clean it out before using the machine again.")
- end
- if prt.getPaperLevel() > 0 then
- print("Uh oh! Something didn't print properly and there's still paper in the printer. Please clean it out before using the machine again.")
- end
- term.setTextColor(colors.white)
- print("Press the button to restart")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement