Advertisement
Catsss

CC imageBinary Turtle

Nov 1st, 2021 (edited)
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. function split(inputstr, sep)
  2.         if sep == nil then
  3.                 sep = "%s"
  4.         end
  5.         local t={}
  6.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  7.                 table.insert(t, str)
  8.         end
  9.         return t
  10. end
  11.  
  12. function toRGB(hex)
  13.     hex = hex:gsub("#","")
  14.     return tonumber(hex)
  15. end
  16.  
  17. os.loadAPI('rgb')
  18. local imageString = http.get('https://gist.githubusercontent.com/BloofersFloofers/3d2bb4e02dc75707fee8eb27bcc8fbe2/raw/b02a343a21b289f1fbc5cadb96de35afd21a7582/ByteArray2').readAll()
  19.  
  20. local fuelEmpty = true
  21. if turtle.getFuelLevel() > 0 then
  22.     fuelEmpty = false
  23. else
  24.     fuelEmpty = true
  25. end
  26.  
  27. print(fuelEmpty)
  28.  
  29. print("Please input X and Y")
  30. local tempString = split(read(),' ')
  31. x,y = tonumber(tempString[1]),tonumber(tempString[2])
  32. print("X: ".. x)
  33. print("Y: ".. y)
  34.  
  35. local imageTable = split(imageString, ', ')
  36. print(#imageTable)
  37.  
  38. for i,v in pairs(imageTable) do
  39.     imageTable[i] = toRGB(v)
  40. end
  41.  
  42. print("Total number of energy for this dig: ".. x*y .." You would need ".. (x*y)/80 .." coal or ".. (x*y)/1000 .." buckets of lava for this dig. Please insert at least one coal or lava in the fourth slot to begin.")
  43.  
  44. while turtle.getFuelLevel() <= 1 do
  45.     sleep(0.1)
  46.     turtle.refuel(64)
  47. end
  48.  
  49. print("Thanks! I will pause if I ever run out of fuel :).")
  50. read()
  51. local total = 0
  52.  
  53. for yC = 1, y do
  54.     for xC = 1, x do
  55.         if turtle.getFuelLevel() <= 1 then
  56.             print("Uh oh! Out of fuel!")
  57.             while turtle.getFuelLevel() <= 1 do
  58.                     turtle.select(1)
  59.                     turtle.refuel(64)
  60.                     sleep(0.1)
  61.             end
  62.         end
  63.         if turtle.getItemCount(2) <= 1 then
  64.             print("Uh oh! Out of white!")
  65.             while turtle.getItemCount(2) <= 1 do
  66.                     sleep(0.1)
  67.             end
  68.         end
  69.         if turtle.getItemCount(3) <= 1 then
  70.             print("Uh oh! Out of black!")
  71.             while turtle.getItemCount(3) <= 1 do
  72.                     sleep(0.1)
  73.             end
  74.         end
  75.        
  76.         total = total + 1
  77.         print(total)
  78.         print(imageTable[total])
  79.         color = colors.fromRGB(imageTable[total],imageTable[total],imageTable[total])
  80.         print(color)
  81.         if color == 1 then
  82.             turtle.select(3)
  83.            else
  84.             turtle.select(2)
  85.         end
  86.         turtle.placeDown()                
  87.         sleep(0.1)
  88.         turtle.forward()
  89.     end
  90.                    
  91.     for i = 1, y do
  92.         turtle.back()
  93.     end
  94.     turtle.turnRight()
  95.     turtle.forward()
  96.     turtle.turnLeft()
  97.    
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement