Barnet

Drop Wool

Jun 19th, 2021 (edited)
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. colors = {"white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
  2. currentColor = 1
  3. colorMap = {}
  4. waitTime = 0
  5.  
  6. function UpdateLog()
  7.   file = fs.open("log", "w")
  8.   file.writeLine(currentColor)
  9.   for i = 1, 16, 1 do
  10.     if colorMap[i] == nil then
  11.       file.writeLine()
  12.     else
  13.       file.writeLine(colorMap[i])
  14.     end
  15.   end
  16.   file.close()
  17. end
  18.  
  19. function ReadFile()
  20.   if arg[2] ~= nil then
  21.     currentColor = tonumber(arg[1])
  22.     UpdateLog()
  23.   else
  24.     file = fs.open("log", "r")
  25.     if file == nil then
  26.       UpdateLog()
  27.     else
  28.       currentColor = tonumber(file.readLine())
  29.       for i = 1, 16, 1 do            
  30.         x = file.readLine()
  31.         if x ~= nil and x ~= "" then
  32.           colorMap[i] = tonumber(x)
  33.         end      
  34.       end
  35.       file.close()
  36.     end
  37.   end
  38. end
  39.  
  40. function CheckColor(color)
  41.   item = turtle.getItemDetail()  
  42.   if item ~= nil and item.name == "minecraft:"..colors[color].."_wool" then
  43.     return true
  44.   end
  45.   return false
  46. end
  47.  
  48. function FindColor(color)
  49.   if CheckColor(color) then
  50.     return true
  51.   end
  52.  
  53.   if colorMap[color] ~= nil then
  54.     turtle.select(colorMap[color])
  55.     if CheckColor(color) then
  56.       return true
  57.     end
  58.   end
  59.  
  60.   for i = 1, 16, 1 do
  61.     turtle.select(i)
  62.     if CheckColor(color) then
  63.       colorMap[color] = i
  64.       return true
  65.     end
  66.   end
  67.  
  68.   return false
  69. end
  70.  
  71. if arg[1] ~= nil then
  72.   waitTime = tonumber(arg[1])
  73. end
  74. ReadFile()
  75. while FindColor(currentColor) do
  76.   turtle.dropDown(1)
  77.   currentColor = currentColor + 1
  78.   if currentColor > 16 then
  79.     currentColor = 1
  80.   end
  81.   UpdateLog()
  82.   if waitTime > 0 then
  83.     sleep(waitTime)
  84.   end
  85. end
  86.  
  87. print("Need more "..colors[currentColor].." wool")
RAW Paste Data