Advertisement
Iepoev

borer

Nov 1st, 2020 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 KB | None | 0 0
  1. -- borer.lua
  2. -- gaat een 9 breed op 9 hoog tunnel graven, tot 256 blocks lang.
  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. -- 32 chests in slot 2
  8. -- een flint and steel in slot 3
  9. -- plaats 1 item van de whitelisted resources in de inventory
  10. -- kies jouw 9x9 vlak en maak een gat in de linkeronderhoek op ooghoogte
  11. -- plaats de borer hierin, voorkant gericht op de richting van de tunnel
  12. -- execute het script
  13.  
  14.  
  15. -- HELPERS
  16. function contains(list, x)
  17.     for _, v in pairs(list) do
  18.         if v == x then return true end
  19.     end
  20.     return false
  21. end
  22.  
  23. function safeForward()
  24.     succ = turtle.forward()
  25.     while not succ do
  26.         turtle.dig()
  27.         succ = turtle.forward()
  28.     end
  29. end
  30.  
  31. function safeDig()
  32.     local bool, block = turtle.inspect()
  33.     if bool then
  34.         if block.name == "minecraft:lava" then
  35.             turtle.select(4)
  36.             turtle.place()
  37.             turtle.refuel()
  38.             turtle.select(1)
  39.         end
  40.         turtle.dig()
  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(4)
  49.             turtle.placeDown()
  50.             turtle.refuel()
  51.             turtle.select(1)
  52.         end
  53.         turtle.digDown()
  54.     end
  55. end
  56.  
  57. function safeDigUp()
  58.     local bool, block = turtle.inspectUp()
  59.     if bool then
  60.         if block.name == "minecraft:lava" then
  61.             turtle.select(4)
  62.             turtle.placeUp()
  63.             turtle.refuel()
  64.             turtle.select(1)
  65.         end
  66.         turtle.digUp()
  67.     end
  68. end
  69.  
  70. -- GLOBALS
  71.  
  72. blacklist = {
  73.     "minecraft:cobblestone",
  74.     "minecraft:andesite",
  75.     "minecraft:diorite",
  76.     "minecraft:granite",
  77.     "minecraft:dirt",
  78.     "minecraft:gravel"
  79.     }
  80.  
  81. whitelist = {
  82.     "minecraft:gold_ore",
  83.     "minecraft:iron_ore",
  84.     "minecraft:diamond",
  85.     "minecraft:coal",
  86.     "minecraft:redstone",
  87.     "minecraft:lapis_lazuli",
  88.     }
  89.  
  90.  
  91. -- DIGGER
  92.  
  93. function digHorizontalSlice(sliceidx, onFloor)
  94.     for i=2,9 do -- horizontal slice
  95.         turtle.dig()
  96.         safeForward()
  97.         safeDigUp()
  98.         safeDigDown()
  99.         if onFloor then
  100.             if (sliceidx == 1  and i == 2) or (sliceidx == 2  and i == 4) or (sliceidx == 4  and i == 7) then
  101.                 turtle.placeDown()
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107.  
  108. -- if torch is true, place a torch
  109. function goThreeUp()
  110.     turtle.up()
  111.     safeDigUp()
  112.     turtle.up()
  113.     safeDigUp()
  114.     turtle.up()
  115.     safeDigUp()
  116.     turtle.turnRight()
  117.     turtle.turnRight()
  118. end
  119.  
  120. function goThreeDown()
  121.     turtle.turnRight()
  122.     turtle.turnRight()
  123.     turtle.down()
  124.     safeDigDown()
  125.     turtle.down()
  126.     safeDigDown()
  127.     turtle.down()
  128.     safeDigDown()
  129. end
  130.  
  131. function digSlice(i)
  132.     turtle.turnRight()
  133.     safeDigUp()
  134.     safeDigDown()
  135.     digHorizontalSlice(i, true)
  136.     goThreeUp()
  137.     digHorizontalSlice(i, false)
  138.     goThreeUp()
  139.     digHorizontalSlice(i, false)
  140.  
  141.     turtle.turnLeft()
  142.     turtle.dig()
  143.     safeForward()
  144.     turtle.turnLeft()
  145.     safeDigUp()
  146.     safeDigDown()
  147.  
  148.     digHorizontalSlice(false)
  149.     goThreeDown()
  150.     digHorizontalSlice(false)
  151.     goThreeDown()
  152.     digHorizontalSlice(false)
  153. end
  154.  
  155. function digChunk()
  156.     for i=1,4 do
  157.         digSlice(i)
  158.         dumpBlacklist()
  159.         turtle.turnRight()
  160.         turtle.dig()
  161.         safeForward()
  162.         safeDigUp()
  163.         safeDigDown()
  164.     end
  165. end
  166.  
  167. -- INVENTORY
  168.  
  169. function dumpBlacklist()
  170.     turtle.select(3) -- fire
  171.     turtle.placeDown()
  172.     for i=10,16 do
  173.         turtle.select(i)
  174.         local item = turtle.getItemDetail()
  175.         if item ~= nil then
  176.             if contains(blacklist, item.name) then -- trash
  177.                 turtle.dropDown(item.count)
  178.             end
  179.         end
  180.     end
  181.     turtle.select(1)
  182. end
  183.  
  184. function clearInventory()
  185.     turtle.back()
  186.     turtle.select(2) -- chest
  187.     chestsuccess = turtle.placeUp()
  188.     turtle.select(3) -- fire
  189.     turtle.placeDown()
  190.     for i=5,16 do
  191.         turtle.select(i)
  192.         local item = turtle.getItemDetail()
  193.         if item ~= nil then
  194.             if item.name == "minecraft:coal" and turtle.getFuelLevel() < 1000 then --refuel
  195.                 turtle.refuel(item.count-1)
  196.             elseif contains(blacklist, item.name) then -- trash
  197.                 turtle.dropDown(item.count)
  198.             elseif contains(whitelist, item.name) and chestsuccess and i < 11 then -- keep 1 in inventory
  199.                 turtle.dropUp(item.count - 1)
  200.             elseif chestsuccess then
  201.                 turtle.dropUp(item.count) --store
  202.             end
  203.         end
  204.     end
  205.     turtle.select(1)
  206.     safeForward()
  207. end
  208.  
  209. -- MAIN
  210.  
  211. for i=1,32 do
  212.     digChunk()
  213.     clearInventory()
  214. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement