Advertisement
wv1106

lavaRefuel

Jul 2nd, 2022
818
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3. print("minimum fuel-level: ")
  4. print("explore (y/n): ")
  5. print("stationary (y/n): ")
  6.  
  7. term.setCursorPos(20, 1)
  8. minFuelLevel = read()
  9. term.setCursorPos(15, 2)
  10. explore = read()
  11. term.setCursorPos(19, 3)
  12. stationary = read()
  13.  
  14. if minFuelLevel == "full"then
  15.     minFuelLevel = turtle.getFuelLimit()
  16. else
  17.     minFuelLevel = tonumber(minFuelLevel)
  18. end
  19.  
  20. if explore == "y" then
  21.     explore = true
  22. else
  23.     explore = false
  24. end
  25.  
  26. if stationary == "y" then
  27.     stationary = true
  28. else
  29.     stationary = false
  30. end
  31. ---------------------------------------------------------------------------------------
  32. function findBucket()
  33.     for i=1,16 do
  34.         local itemD = turtle.getItemDetail(i)
  35.         if not (itemD==nil) then
  36.             if itemD.name=="minecraft:bucket" then
  37.                 turtle.select(i)
  38.                 return true
  39.             end
  40.         end
  41.     end
  42.     return false
  43. end
  44.  
  45.  
  46. ---------------------------------------------------------------------------------------
  47. function forward()
  48.     for i=1,10 do
  49.         if turtle.forward() then
  50.             return true
  51.         end
  52.         turtle.attack()
  53.     end
  54.     return false
  55. end
  56.  
  57. function down()
  58.     for i=1,10 do
  59.         if turtle.down() then
  60.             return true
  61.         end
  62.     end
  63.     return false
  64. end
  65.  
  66. function up()
  67.     while not turtle.up() do
  68.         turtle.digUp()
  69.         turtle.attackUp()
  70.     end
  71. end
  72.  
  73. function backTrack()
  74.     turtle.turnLeft()
  75.     turtle.turnLeft()
  76.  
  77.     for i, dir in ipairs(moved) do
  78.         if dir=="f" then
  79.             forward()
  80.         else
  81.             up()
  82.         end
  83.     end
  84. end
  85.  
  86. -----------------------------------------------------------------------------------------
  87. paintutils.drawFilledBox(1, 1, 39, 19, colors.red)
  88. term.setBackgroundColor(colors.red)
  89. term.setTextColor(colors.white)
  90. term.setCursorPos(12, 7)
  91. term.write("nu bucket")
  92. while not findBucket() do
  93.     sleep(0.5)
  94. end
  95.  
  96. paintutils.drawFilledBox(1, 1, 39, 19, colors.orange)
  97. term.setBackgroundColor(colors.orange)
  98. term.setTextColor(colors.white)
  99. term.setCursorPos(12, 7)
  100. term.write("filling up")
  101. moved = {}
  102. if explore then
  103.     hasBlock, blockData = turtle.inspectDown()
  104.     while ((not (blockData.name == "minecraft:lava")) or blockData.name==nil) do
  105.         if (not hasBlock) then
  106.             if not down() then
  107.                 backTrack()
  108.                 paintutils.drawFilledBox(1, 1, 39, 19, colors.orange)
  109.                 term.setBackgroundColor(colors.orange)
  110.                 term.setTextColor(colors.white)
  111.                 term.setCursorPos(2, 7)
  112.                 term.write("obstacle Found while exploring")
  113.  
  114.                 os.pullEvent("key")
  115.                    
  116.                 os.reboot()
  117.             else
  118.                 table.insert(moved, 1, "d")
  119.             end
  120.            
  121.         else
  122.             if not forward() then
  123.                 backTrack()
  124.                 paintutils.drawFilledBox(1, 1, 39, 19, colors.orange)
  125.                 term.setBackgroundColor(colors.orange)
  126.                 term.setTextColor(colors.white)
  127.                 term.setCursorPos(2, 7)
  128.                 term.write("obstacle Found while exploring")
  129.  
  130.                 os.pullEvent("key")
  131.                    
  132.                 os.reboot()
  133.             else
  134.                 table.insert(moved, 1, "f")
  135.             end
  136.         end
  137.         hasBlock, blockData = turtle.inspectDown()
  138.     end
  139. end
  140.  
  141. if not findBucket() then
  142.     paintutils.drawFilledBox(1, 1, 39, 19, colors.red)
  143.     term.setBackgroundColor(colors.red)
  144.     term.setTextColor(colors.white)
  145.     term.setCursorPos(12, 7)
  146.     term.write("no bucket")
  147.     backTrack()
  148.     os.pullEvent("key")
  149.    
  150.     os.reboot()
  151. end
  152.  
  153. while turtle.getFuelLevel() <= minFuelLevel do
  154.     turtle.placeDown()
  155.     turtle.refuel()
  156.     if not stationary then
  157.         if forward() then
  158.             table.insert(moved, 1, "f")
  159.         else
  160.             backTrack()
  161.             paintutils.drawFilledBox(1, 1, 39, 19, colors.orange)
  162.             term.setBackgroundColor(colors.orange)
  163.             term.setTextColor(colors.white)
  164.             term.setCursorPos(2, 7)
  165.             term.write("obstacle Found while filling")
  166.  
  167.             os.pullEvent("key")
  168.                
  169.             os.reboot()
  170.         end
  171.     end
  172. end
  173.  
  174. backTrack()
  175.  
  176. paintutils.drawFilledBox(1, 1, 39, 19, colors.lime)
  177. term.setBackgroundColor(colors.lime)
  178. term.setTextColor(colors.white)
  179. term.setCursorPos(12, 7)
  180. term.write("finished")
  181.  
  182. os.pullEvent("key")
  183.    
  184. os.reboot()
Advertisement
RAW Paste Data Copied
Advertisement