Advertisement
Iepoev

borer_v2

Nov 9th, 2020 (edited)
1,864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.78 KB | None | 0 0
  1. -- borer.lua
  2. -- gaat een 9 breed op 9 hoog tunnel graven, zolang hij torches in slot 1 heeft om te plaatsen.
  3. -- zal iedere 8 blocks een torch zetten en zijn inventory legen, door items in de blacklist te yeeten en de rest te storen in een chest
  4.  
  5. -- Primen door:
  6. -- 64 torches in slot 1
  7. -- minstens 10 chests in slot 2
  8. -- een empty bucket in slot 3
  9. -- kies jouw 9x9 vlak en maak een gat in de linkeronderhoek op ooghoogte
  10. -- plaats de borer hierin, voorkant gericht op de richting van de tunnel
  11. -- execute het script
  12.  
  13.  
  14. -- HELPERS
  15. function contains(list, x)
  16.     for _, v in pairs(list) do
  17.         if v == x then return true end
  18.     end
  19.     return false
  20. end
  21.  
  22. function safeForward()
  23.     succ = turtle.forward()
  24.     while not succ do
  25.         turtle.dig()
  26.         succ = turtle.forward()
  27.     end
  28. end
  29.  
  30. function safeDig()
  31.     local bool, block = turtle.inspect()
  32.     if bool then
  33.         if block.name == "minecraft:lava" then
  34.             turtle.select(3)
  35.             turtle.place()
  36.             turtle.refuel()
  37.             turtle.select(1)
  38.         else
  39.             turtle.dig()
  40.         end
  41.     end
  42. end
  43.  
  44. function safeDigDown()
  45.     local bool, block = turtle.inspectDown()
  46.     if bool then
  47.         if block.name == "minecraft:lava" then
  48.             turtle.select(3)
  49.             turtle.placeDown()
  50.             turtle.refuel()
  51.             turtle.select(1)
  52.         else
  53.             turtle.digDown()
  54.         end
  55.     end
  56. end
  57.  
  58. function safeDigUp()
  59.     local bool, block = turtle.inspectUp()
  60.     if bool then
  61.         if block.name == "minecraft:lava" then
  62.             turtle.select(3)
  63.             turtle.placeUp()
  64.             turtle.refuel()
  65.             turtle.select(1)
  66.         else
  67.             turtle.digUp()
  68.         end
  69.     end
  70. end
  71.  
  72. function lavaPresent()
  73.     isPresent = false
  74.  
  75.     local boolfront, blockfront = turtle.inspect()
  76.     if boolfront then
  77.         if blockfront.name == "minecraft:lava" or blockfront.name == "minecraft:flowing_lava" then
  78.             isPresent = true
  79.         end
  80.     end
  81.  
  82.  
  83.     local boolup, blockup = turtle.inspectUp()
  84.     if boolup then
  85.         if blockup.name == "minecraft:lava" or blockup.name == "minecraft:flowing_lava" then
  86.             isPresent = true
  87.         end
  88.     end
  89.  
  90.     local booldown, blockdown = turtle.inspectDown()
  91.     if booldown then
  92.         if blockdown.name == "minecraft:lava" or blockdown.name == "minecraft:flowing_lava" then
  93.             isPresent = true
  94.         end
  95.     end
  96.  
  97.     return isPresent
  98. end
  99.  
  100. -- GLOBALS
  101.  
  102. blacklist = {
  103.     "minecraft:cobblestone",
  104.     "minecraft:andesite",
  105.     "minecraft:diorite",
  106.     "minecraft:granite",
  107.     "minecraft:dirt",
  108.     "minecraft:gravel"
  109.     }
  110.  
  111. -- DIGGER
  112.  
  113. function digHorizontalSlice(sliceidx, onFloor)
  114.     for i=2,9 do -- horizontal slice
  115.         turtle.dig()
  116.         safeForward()
  117.         safeDigUp()
  118.         safeDigDown()
  119.         if onFloor then
  120.             if (sliceidx == 1  and i == 2) or (sliceidx == 2  and i == 4) or (sliceidx == 4  and i == 7) then
  121.                 turtle.placeDown()
  122.             end
  123.         end
  124.     end
  125. end
  126.  
  127.  
  128. -- if torch is true, place a torch
  129. function goThreeUp()
  130.     turtle.up()
  131.     safeDigUp()
  132.     turtle.up()
  133.     safeDigUp()
  134.     turtle.up()
  135.     safeDigUp()
  136.     turtle.turnRight()
  137.     turtle.turnRight()
  138. end
  139.  
  140. function goThreeDown()
  141.     turtle.turnRight()
  142.     turtle.turnRight()
  143.     turtle.down()
  144.     safeDigDown()
  145.     turtle.down()
  146.     safeDigDown()
  147.     turtle.down()
  148.     safeDigDown()
  149. end
  150.  
  151. function digSlice(i)
  152.     turtle.turnRight()
  153.     safeDigUp()
  154.     safeDigDown()
  155.     digHorizontalSlice(i, true)
  156.     goThreeUp()
  157.     digHorizontalSlice(i, false)
  158.     goThreeUp()
  159.     digHorizontalSlice(i, false)
  160.  
  161.     turtle.turnLeft()
  162.     turtle.dig()
  163.     safeForward()
  164.     turtle.turnLeft()
  165.     safeDigUp()
  166.     safeDigDown()
  167.  
  168.     digHorizontalSlice(false)
  169.     goThreeDown()
  170.     digHorizontalSlice(false)
  171.     goThreeDown()
  172.     digHorizontalSlice(false)
  173. end
  174.  
  175. function digChunk()
  176.     for i=1,4 do
  177.         digSlice(i)
  178.         dumpBlacklist()
  179.         turtle.turnRight()
  180.         turtle.dig()
  181.         safeForward()
  182.         safeDigUp()
  183.         safeDigDown()
  184.     end
  185. end
  186.  
  187. -- INVENTORY
  188.  
  189. function dumpBlacklist()
  190.     for i=4,16 do
  191.         turtle.select(i)
  192.         local item = turtle.getItemDetail()
  193.         if item ~= nil then
  194.             if contains(blacklist, item.name) then -- trash
  195.                 turtle.dropDown(item.count)
  196.             end
  197.         end
  198.     end
  199.     turtle.select(1)
  200. end
  201.  
  202. function clearInventory()
  203.     dumpBlacklist()
  204.  
  205.     backpackFull = False
  206.     for i = 4,16 do
  207.         if turtle.getItemCount(i) >= 60 then
  208.             backpackFull = true
  209.         end
  210.     end
  211.    
  212.     isPresent = lavaPresent()
  213.  
  214.     if backpackFull and not isPresent then
  215.         turtle.back()
  216.         turtle.select(2) -- chest
  217.         if turtle.placeDown() then
  218.             print("placed Chest at chunk:")
  219.             print(chunkCounter)
  220.             if backpackFull then
  221.                 for i=4,16 do -- clear junk
  222.                     turtle.select(i)
  223.                     local item = turtle.getItemDetail()
  224.                     if item ~= nil then
  225.                         if item.name == "minecraft:coal" and turtle.getFuelLevel() < 1000 then --refuel
  226.                             turtle.refuel(item.count-1)
  227.                         else -- keep 1 in inventory
  228.                             turtle.dropDown(item.count)
  229.                         end
  230.                     end
  231.                 end
  232.             end
  233.         end
  234.  
  235.         turtle.select(1)
  236.         safeForward()
  237.     end
  238. end
  239.  
  240. -- MAIN
  241.  
  242. chunkCounter = 0
  243.  
  244. while turtle.getItemCount(1) > 0 do
  245.     digChunk()
  246.     chunkCounter = chunkCounter + 1
  247.     clearInventory(chunkCounter)
  248. end
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement