Advertisement
sasaa86

Tunneling script for Computercraft turtle

Aug 24th, 2017 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. -- computercraft tunneling program 1x3 for strip-minning
  2. -- options for Enderchest, torches, normal chests and loot-only
  3. -- ########## NOT READY #############
  4.  
  5. local useEnderChest = false                                 -- place a enderchest, dump stuff in it and collect chest?
  6. local enderChestSlot = 2                                -- slot to place enderchest
  7. local useNormalChest = false                                -- place a chest, dump stuff in it and move on?
  8. local normalChestSlot = 3                               -- slot to place chests
  9. local lootOnly = true                                   -- discard dirt cobble etc?
  10. local useTorch = false                                  -- place torches along path?
  11. local torchSlot = 1                                 -- turtleslot to put torches
  12. local torchInterval = 8                                 -- place torch every X blocks
  13. local returnToStart = false                             --
  14. local tLenght = 30                                  -- tunnels for 30 blocks
  15.  
  16. torchNeeded = math.floor(tLenght / torchInterval)                   -- calculating needed torches
  17.  
  18.  
  19. shell.run("clear")
  20.  
  21. if turtle.getItemDetail(enderChestSlot) ~= "ender_chest" then
  22.     print("no Enderchest found in slot ".. enderChestSlot)
  23. end
  24. if turtle.getItemDetail(normalChestSlot) ~= "chest" then
  25.     print("no chest found in slot ".. normalChestSlot)
  26. end
  27.  
  28. if turtle.detectDown() then
  29.     turtle.up()
  30. end
  31. for i=0,tLenght do
  32.     while turtle.digUp() do
  33.         -- waiting for gravel or sand to fall down
  34.         sleep(.2)
  35.     end
  36.     while turtle.dig() do
  37.         -- waiting for gravel or sand to fall down
  38.         sleep(.2)
  39.     end
  40.     turtle.forward()
  41.     turtle.digDown()
  42.     if turtle.getItemCount(16) ~= 0 then
  43.         if useEnderChest then
  44.             turtle.select(enderChestSlot)
  45.             turtle.placeUp()
  46.             if lootOnly then
  47.                 for slot=4, 16 do
  48.                     info = turtle.getItemDetail(slot)
  49.                     if info.name ~= "cobblestone" or info.name ~= "dirt" or info.name ~= "gravel" or info.name ~= "sand" then
  50.                         turtle.select(slot)
  51.                         turtle.dropUp()
  52.                     else
  53.                         turtle.select(slot)
  54.                         turtle.dropDown()
  55.                     end
  56.                 end
  57.             else
  58.                 for slot=4, 16 do
  59.                     turtle.select(slot)
  60.                     turtle.dropUp()
  61.                 end
  62.             end
  63.             turtle.digUp() -- pickup enderchest
  64.             for a=1,16 do
  65.                 temp1 = turtle.getItemDetail(enderChestSlot)
  66.                 if temp1.name == "ender_chest" then
  67.                     turtle.select(a)
  68.                     turtle.transferTo(enderChestSlot)
  69.                 end
  70.             end
  71.         else if useNormalChest then
  72.             turtle.select(normalChestSlot)
  73.             if lootOnly then
  74.                 for slot=4, 16 do
  75.                     info = turtle.getItemDetail(slot)
  76.                     if info.name ~= "cobblestone" or info.name ~= "dirt" or info.name ~= "gravel" or info.name ~= "sand" then
  77.                         turtle.select(slot)
  78.                         turtle.dropUp()
  79.                     else
  80.                         turtle.select(slot)
  81.                         turtle.dropDown()
  82.                     end
  83.                 end
  84.             else
  85.                 for slot=4, 16 do
  86.                     turtle.select(slot)
  87.                     turtle.dropUp()
  88.                 end
  89.             end
  90.             turtle.digUp() -- pickup chest
  91.             for a=1,16 do
  92.                 temp2 = turtle.getItemDetail(normalChestSlot)
  93.                 if temp2.name == "chest" then
  94.                     turtle.select(a)
  95.                     turtle.transferTo(normalChestSlot)
  96.                 end
  97.             end
  98.         end
  99.     end
  100.     if useTorch then
  101.         if i == torchInterval then
  102.             torchInterval = torchInterval+torchInterval
  103.             turtle.select(torchSlot)
  104.             if turtle.getItemCount(torchSlot) ~= 0 then
  105.                 turtle.placeDown()
  106.             else
  107.                 turtle.down()
  108.                 while turtle.getItemCount(torchSlot) < torchNeeded do
  109.                     shell.run("clear")
  110.                     print("Torches needed, Will resume when replenished.")
  111.                     print("Would need " .. torchNeeded .. "torches.")
  112.                     sleep(3)
  113.                 end
  114.                 shell.run("clear")
  115.                 turtle.up()
  116.                 print("here we go again.")
  117.             end
  118.             turtle.select(4)
  119.         end
  120.     end
  121. end
  122. end
  123. if returnToStart then
  124.     for I=0,tLength do
  125.         turtle.back()
  126.     end
  127.     print("Done, returned to start!")
  128. else
  129.     print("Done, take me away!")
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement