Advertisement
AdditionalPylons

printer_cl.lua

Jul 9th, 2024 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local prt = peripheral.find("printer")
  2. local args = {...}
  3.  
  4. local data = {fs.open("/printer/data.lua","r")}
  5. if data[1]==nil then print("data.json cannot be opened: "..data[2]) end
  6. local setup = textutils.unserialise(data[1].readAll())
  7. data[1].close()
  8.  
  9. peripheral.call("minecraft:chest_"..setup.chest_paper,"pushItems","minecraft:hopper_"..setup.printer_paper,1,1)
  10. 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
  11. local file
  12. if args[1]==nil then
  13.     file = "/printer/canvas.nfp"
  14. else
  15.     file = shell.dir()..args[1]
  16. end
  17. while not prt.newPage() do sleep(0.05) end
  18. if not fs.exists(file) then
  19.     local size = {prt.getPageSize()}
  20.     print(size[1],size[2])
  21.     local f = fs.open(file,"w")
  22.     for i=1,size[2] do
  23.         for i=1,size[1] do
  24.             f.write("0")
  25.         end
  26.         f.write("\n")
  27.     end
  28.     f.close()
  29. end
  30. prt.endPage()
  31. shell.run("/printer/rspaint "..file)
  32. print("Printing 0/15 (0)")
  33. for i=1,15 do
  34.     local f = fs.open(file,"r")
  35.     write("Waiting for paper")
  36.     while peripheral.call("minecraft:chest_"..setup.printer_output,"pushItems","minecraft:hopper_"..setup.printer_paper,1,1)==0 do
  37.         sleep(0.05)
  38.         write(".")
  39.     end
  40.     print(" Done")
  41.     peripheral.call("minecraft:chest_"..setup.chests_ink_start+i,"pushItems","minecraft:hopper_"..setup.printer_ink,1,1)
  42.     write("Waiting for ink")
  43.     while not prt.newPage() do
  44.         sleep(0.05)
  45.         write(".")
  46.     end
  47.     print(" Done")
  48.     local color_char = colors.toBlit(2^i)
  49.     b = f.read(1)
  50.     while b~=nil do
  51.         if b~="\n" then
  52.             if b==color_char then
  53.                 prt.write("\x7f")
  54.             else
  55.                 local pos = {prt.getCursorPos()}
  56.                 prt.setCursorPos(pos[1]+1,pos[2])
  57.             end
  58.         else
  59.             local pos = {prt.getCursorPos()}
  60.             prt.setCursorPos(1,pos[2]+1)
  61.         end
  62.         b = f.read(1)
  63.     end
  64.     prt.endPage()
  65.     f.close()
  66.     print("Printing "..i.."/15 ("..color_char..")")
  67. end
  68. print("Done!")
  69. term.setTextColor(colors.red)
  70. if prt.getInkLevel() > 0 then
  71.     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.")
  72. end
  73. if prt.getPaperLevel() > 0 then
  74.     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.")
  75. end
  76. term.setTextColor(colors.white)
  77. print("Press the button to restart")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement