Advertisement
Blackhome

Mining

Oct 5th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.06 KB | None | 0 0
  1. -- Drops Items without chests.
  2. -- By hitting chests Turtle don't take Items.
  3.  
  4. local Glength = 30
  5. local NumG = tonumber(io.read())
  6. local Side = tonumber(io.read())    -- 0 == right ; 1 == left
  7. local i = 0
  8. local NotWishedItems = {}
  9. NotWishedItems[0] = "minecraft:dirt"
  10. NotWishedItems[1] = "minecraft:cobblestone"
  11. NotWishedItems[2] = "minecraft:stone"
  12. NotWishedItems[3] = "minecraft:obsidian"
  13. NotWishedItems[4] = "minecraft:sand"
  14. NotWishedItems[5] = "minecraft:gravel"
  15. NotWishedItems[6] = "minecraft:rail"
  16. NotWishedItems[7] = "minecraft:planks"
  17. NotWishedItems[8] = "minecraft:fence"
  18. NotWishedItems[9] = "bluepower:marble"
  19. NotWishedItems[10] = "minecraft:torch"
  20. NotWishedItems[11] = "minecraft:trapped_chest"
  21. NotWishedItems[12] = "minecraft:flowing_water"
  22. NotWishedItems[13] = "minecraft:flowing_lava"
  23. NotWishedItems[14] = "minecraft:chest"
  24.  
  25. function turn()
  26.     turtle.turnLeft()
  27.     turtle.turnLeft()
  28. end
  29. function up()
  30.     while turtle.detectUp() == true do
  31.         turtle.digUp()
  32.         sleep(1)
  33.     end
  34.     turtle.up()
  35. end
  36. function down()
  37.     while turtle.detectDown() == true do
  38.         turtle.digDown()
  39.         sleep(1)
  40.     end
  41.     turtle.down()
  42. end
  43. function forward()
  44.     while turtle.detect() == true do
  45.         turtle.dig()
  46.         sleep(1)
  47.     end
  48.     turtle.forward()
  49. end
  50. function back()
  51.     turn()
  52.     forward()
  53.     turn()
  54. end
  55. function placeChest()
  56.     local cnt = 1
  57.     while cnt < 17 do
  58.         data = turtle.getItemDetail(cnt)
  59.         if (data) then
  60.             if ((data.name == "minecraft:trapped_chest") or (data.name == "minecraft:chest")) then
  61.                 turtle.select(cnt)
  62.                 turtle.place()
  63.                 cnt = 16
  64.             elseif (cnt == 16) then
  65.                 local a = 0
  66.                 while (a == 0) do
  67.                     print("Can't found any chest.")
  68.                     print("Please enter new ones.")
  69.                     print("After finishing, please write a number which is bigger then nil")
  70.                     a = tonumber(io.read())
  71.                 end
  72.                 placeChest()
  73.             end
  74.         elseif (cnt == 16) then
  75.             local a = 0
  76.             while (a == 0) do
  77.                 print("Can't found any chest.")
  78.                 print("Please enter new ones.")
  79.                 print("After finishing, please write a number which is bigger then nil")
  80.                 a = tonumber(io.read())
  81.             end
  82.             placeChest()
  83.         end
  84.         cnt = cnt + 1
  85.     end
  86. end
  87. function placeLightUp()
  88.     local cnt = 1
  89.     while cnt < 17 do
  90.         data = turtle.getItemDetail(cnt)
  91.         if (data) then
  92.             if (data.name == "minecraft:torch") then
  93.                 turtle.select(cnt)
  94.                 turtle.placeUp()
  95.                 cnt = 16
  96.             elseif (cnt == 16) then
  97.                 local a = 0
  98.                 while (a == 0) do
  99.                     print("Can't found any torch.")
  100.                     print("Please enter new ones.")
  101.                     print("After finishing, please write a number which is bigger then nil")
  102.                     a = tonumber(io.read())
  103.                 end
  104.                 placeLightUp()
  105.             end
  106.         elseif (cnt == 16) then
  107.             local a = 0
  108.             while (a == 0) do
  109.                 print("Can't found any torch.")
  110.                 print("Please enter new ones.")
  111.                 print("After finishing, please write a number which is bigger then nil")
  112.                 a = tonumber(io.read())
  113.             end
  114.             placeLightUp()
  115.         end
  116.         cnt = cnt + 1
  117.     end
  118. end
  119. function IsAWishedItem(_name)
  120.     local cnt = 0
  121.     local Nnwi = table.getn(NotWishedItems)
  122.     while (cnt < Nnwi) do
  123.         if (_name == NotWishedItems[cnt]) then
  124.             return false
  125.         end
  126.         cnt = cnt + 1
  127.     end
  128.     return true
  129. end
  130. function lookingForRessources()
  131.     local cnt = 0
  132.     while (cnt < 6) do
  133.         if (cnt == 0 and turtle.detectUp() == true) then
  134.             local success, data = turtle.inspectUp()
  135.             if (success == true and IsAWishedItem(data.name) == true) then
  136.                 up()
  137.                 lookingForRessources()
  138.                 down()
  139.             end
  140.         elseif (cnt == 1 and turtle.detectDown() == true) then
  141.             local success, data = turtle.inspectDown()
  142.             if (success == true and IsAWishedItem(data.name) == true) then
  143.                 down()
  144.                 lookingForRessources()
  145.                 up()
  146.             end
  147.         elseif (cnt > 1 and cnt < 6) then
  148.             local success, data = turtle.inspect()
  149.             if (success == true and IsAWishedItem(data.name) == true and turtle.detect()) then
  150.                 forward()
  151.                 lookingForRessources()
  152.                 back()
  153.             end
  154.             turtle.turnRight()
  155.         end
  156.         cnt = cnt + 1
  157.     end
  158.  
  159. end
  160. function dropAllFoundItems()
  161.     local cnt = 1
  162.     local CobDropNum = 0;
  163.     while cnt < 17 do
  164.         turtle.select(cnt)
  165.         local data = turtle.getItemDetail()
  166.         if (data) then
  167.             if (data.name == "minecraft:cobblestone") then
  168.                 if (data.count < 3) then
  169.                     turtle.drop()
  170.                 elseif (CobDropNum == 1) then
  171.                     turtle.drop()
  172.                 else
  173.                     turtle.drop(data.count - 3)
  174.                     CobDropNum = 1
  175.                 end
  176.             elseif (data.name == "minecraft:torch") then
  177.                 cnt = cnt
  178.             elseif (data.name == "minecraft:trapped_chest") then
  179.                 cnt = cnt
  180.             elseif (data.name == "minecraft:chest") then
  181.                 cnt = cnt
  182.             else
  183.                 turtle.drop()
  184.             end
  185.         end
  186.         cnt = cnt + 1
  187.         if (cnt == 16 and CobDropNum == 0) then
  188.             local a = 0
  189.             while (a == 0) do
  190.                 print("There are not enough Cobblestones")
  191.                 print("Please make sure that there are at least")
  192.                 print("three Cobblestones.")
  193.                 print("After finishing, please write a number which is bigger then nil")
  194.                 a = tonumber(io.read())
  195.                 dropAllFoundItems()
  196.             end
  197.         end
  198.     end
  199. end
  200. function nextGang()
  201.     if (Side == 1) then
  202.         turtle.turnRight()
  203.     elseif (Side == 0) then
  204.         turtle.turnLeft()
  205.     end
  206.     placeChest()
  207.     dropAllFoundItems()
  208.     turn()
  209.     forward()
  210.     forward()
  211.     forward()
  212.     if (Side == 1) then
  213.         turtle.turnLeft()
  214.     elseif (Side == 0) then
  215.         turtle.turnRight()
  216.     end
  217. end
  218. function placeCobblestone()
  219.     local cnt = 0
  220.     while (cnt < 16) do
  221.         local data = turtle.getItemDetail(cnt+1)
  222.  
  223.         if (data) then
  224.             if (data.name == "minecraft:cobblestone") then
  225.                 turtle.select(cnt+1)
  226.                 turtle.place()
  227.             end
  228.         end
  229.         cnt = cnt + 1
  230.     end
  231. end
  232.  
  233.  
  234. while i < NumG do
  235.     local Gl = 0
  236.     while Gl < Glength do
  237.         forward()
  238.         lookingForRessources()              -- not exists now
  239.         up()
  240.         lookingForRessources()              -- not exists now
  241.         if (((Gl+1) % 10 == 0) or ((Gl+1) == Glength)) then
  242.             turtle.turnRight()
  243.             if (turtle.detect() == false) then
  244.                 placeCobblestone() 
  245.             end
  246.             turtle.turnLeft()
  247.         end
  248.         down()
  249.         if (((Gl+1) % 10 == 0) or ((Gl+1) == Glength)) then
  250.             placeLightUp()
  251.         end
  252.         Gl = Gl + 1
  253.     end
  254.     turn()
  255.     Gl = 0
  256.     while (Gl < Glength) do
  257.         turtle.forward()
  258.         Gl = Gl + 1
  259.     end
  260.     nextGang()
  261.     i = i + 1
  262. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement