Advertisement
Shaka01

test of patience

Feb 19th, 2023 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. dropApple = true
  2. dropPaper = true
  3. dropCookie = true
  4. dropFish = false
  5.  
  6.  
  7. function dropUp()
  8.     count = turtle.getItemCount()
  9.     if count > 0 then
  10.         if turtle.dropUp() == false then
  11.             term.clear()
  12.             term.setCursorPos(1,1)
  13.             print("Inventory full.")
  14.             repeat
  15.                 sleep(0.5)
  16.             until turtle.dropUp()
  17.         end
  18.     end
  19. end
  20.  
  21.  
  22. function scanInv()
  23.     for i = 1, 16 do
  24.         data = turtle.getItemDetail(i)
  25.         if data then
  26.             if data.name == "minecraft:paper" and dropPaper == true then
  27.                 turtle.select(i)
  28.                 turtle.dropDown()
  29.             elseif data.name == "minecraft:apple" and dropApple == true then
  30.                 turtle.select(i)
  31.                 turtle.dropDown()
  32.             elseif data.name == "minecraft:cookie" and dropCookie == true then
  33.                 turtle.select(i)
  34.                 turtle.dropDown()
  35.             elseif data.name == "minecraft:pufferfish" and dropFish == true then
  36.                 turtle.select(i)
  37.                 turtle.dropDown()
  38.             elseif data.name ~= "minecraft:barrel" then
  39.                 turtle.select(i)
  40.                 dropUp()
  41.             end
  42.         end
  43.     end
  44. end
  45.  
  46. function findItem(item)
  47.     for i = 1, 16 do
  48.         local data = turtle.getItemDetail(i)
  49.             if data then
  50.                 if data.name == item then
  51.                     turtle.select(i)
  52.                 end
  53.             end
  54.     end
  55. end
  56.  
  57. function centerText(monitor, y, text)
  58.   local w, h = monitor.getSize()
  59.   local x = math.floor((w - string.len(text) + 2) / 2)
  60.   monitor.setCursorPos(x , y)
  61.   print(text)
  62. end
  63.  
  64. function findBarrelCount()
  65.     barrelCount = 0
  66.     for i = 1, 16 do
  67.         local data = turtle.getItemDetail(i)
  68.         if data then
  69.             if data.name == "minecraft:barrel" then
  70.              barrelCount = barrelCount + 1
  71.             end
  72.         end
  73.     end
  74. return barrelCount
  75. end
  76.  
  77. function saveCounter(number)
  78.   local file = io.open("counter", "w")  -- open file in write mode
  79.   file:write(number)  -- write number to file
  80.   file:close()  -- close file
  81. end
  82.  
  83. function readCounter()
  84.   local file = io.open("counter", "r")  -- open file in read mode
  85.   if file then
  86.     local number = tonumber(file:read("*all"))  -- read the entire file as a string and convert to a number
  87.     file:close()  -- close file
  88.     return number
  89.   else
  90.     return nil  -- file doesn't exist or couldn't be opened
  91.   end
  92. end
  93.  
  94. function formatNumber(number)
  95.   local formatted = tostring(number)
  96.   local k = #formatted % 3
  97.   if k == 0 then k = 3 end
  98.   formatted = formatted:sub(1, k) .. formatted:sub(k+1):gsub("(%d%d%d)", ".%1")
  99.   return formatted
  100. end
  101.  
  102. function identifySpecialBarrel(slot)
  103.     local data = turtle.getItemDetail(slot, true)
  104.     if data then
  105.         if data.name == "minecraft:barrel" then
  106.             if data.lore then
  107.              return true
  108.             else
  109.              return false
  110.             end
  111.         else
  112.             print("No Barrel")
  113.         end
  114.     end
  115. end
  116.  
  117. local file = io.open("counter", "r")
  118. if not file then
  119.   file = io.open("counter", "w")
  120.   file:write("1")
  121.   file:close()
  122. end
  123.  
  124.  
  125. cycleCount = readCounter()
  126.  
  127.  
  128. while true do
  129. term.clear()
  130. term.setCursorPos(1,1)
  131. cycleCount = readCounter()
  132. term.setTextColor(colors.yellow)
  133. centerText(term, 4, "Currently running cycle")
  134. term.setTextColor(colors.green)
  135. displayCount = formatNumber(cycleCount)
  136. centerText(term, 7, displayCount)
  137. local bool, blockFront = turtle.inspect()
  138. if blockFront.name ~= "minecraft:barrel" then
  139.     findItem("minecraft:barrel")
  140.     slot = turtle.getSelectedSlot()
  141.     if identifySpecialBarrel(slot) == true then
  142.         turtle.place()
  143.         turtle.select(1)
  144.     end
  145. else
  146.     turtle.select(1)
  147.     repeat until turtle.suck() == false
  148.     scanInv()
  149.     if turtle.dig() then
  150.         cycleCount = cycleCount + 1
  151.         saveCounter(cycleCount)
  152.     else
  153.         print("Stuff went sideways.")
  154.     end
  155. end
  156.  
  157. for i = 1, 2 do
  158.     findItem("minecraft:barrel")
  159.     slot = turtle.getSelectedSlot()
  160.     if identifySpecialBarrel(slot) == true then
  161.         turtle.place()
  162.     else
  163.         dropUp()
  164.     end
  165. end
  166.  
  167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement