Advertisement
Keystyles

Simplest Miner

Nov 25th, 2017
10,695
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.89 KB | None | 1 0
  1. --Simplest miner v0.2
  2. --17 Nov 27
  3. --  pastebin get C93d6FX6 cm
  4. --  delete cm
  5. --************
  6. --
  7. --This mining program is filled with
  8. --assumptions, generalizations, and
  9. --bugs. I will update/maintain when
  10. --possible. Feel free to suggest changes
  11. --
  12. --Written by : Keystyles
  13. --************
  14.  
  15.  
  16. --************
  17. --Constants/Initialization
  18. --************
  19.  
  20. ----Orientation (start location = 0,0,0)
  21. local currX = 0
  22. local currY = 0
  23. local currZ = 0
  24.  
  25. local width = 15
  26.  
  27. --***********
  28. --Functions
  29. --***********
  30.  
  31. function checkJunk(name) --check the data from the inspect and return true if it's junk; add "--" before both lines to remove an entry
  32.     if name == "minecraft:stone" then
  33.         return false
  34.     elseif name == "minecraft:cobblestone" then
  35.         return false
  36.     elseif name == "minecraft:gravel" then
  37.         return false
  38.     elseif name == "minecraft:dirt" then
  39.         return false
  40.     elseif name == "minecraft:water" then
  41.         return false
  42.     elseif name == "minecraft:red_mushroom" then
  43.         return false
  44.     --elseif name == "minecraft:redstone_ore" then
  45.     --  return false
  46.     --elseif name == "minecraft:coal_ore" then
  47.     --  return false
  48.     elseif name == "ProjRed:Exploration:projectred.exploration.stone" then --Marble, need to find correct name*
  49.         return false
  50.     elseif name == "minecraft:sand" then
  51.         return false
  52.     elseif name == "minecraft:netherrack" then
  53.         return false
  54.     elseif name == "Botania:stone" then --this is all Botania stones; diorite, granite, etc
  55.         return false
  56.     elseif name == "Botania:mushroom" then  --this is all Botania stones; diorite, granite, etc
  57.         return false
  58.     elseif name == "chisel:limestone" then
  59.         return false
  60.     elseif name == "chisel:andesite" then
  61.         return false
  62.     elseif name == "chisel:diorite" then
  63.         return false
  64.     elseif name == "chisel:granite" then
  65.         return false
  66.     elseif name == "chisel:marble" then
  67.         return false
  68.     elseif name == "BiomesOPlenty:flowers" then
  69.         return false
  70.     elseif name == "BiomesOPlenty:flowers2" then
  71.         return false
  72.     else
  73.         return true
  74.     end
  75. end
  76.  
  77. function turtleUp()
  78.     x = turtle.up()
  79.     while x == false do
  80.         if turtle.digUp() then
  81.         x = turtle.up()
  82.         else
  83.             if turtle.inspectUp() then
  84.                 if turtle.digUp() then
  85.                     x=turtle.up()
  86.                 else
  87.                     return false
  88.                 end
  89.             else
  90.                 turtle.attackUp()
  91.                 x = turtle.up()
  92.             end
  93.         end
  94.     end
  95.     return true
  96. end
  97.  
  98. function turtleDown()
  99.     x = turtle.down()
  100.     while x == false do
  101.         if turtle.digDown() then
  102.             x = turtle.down()
  103.         else
  104.             if turtle.inspectDown() then
  105.                 if turtle.digDown() then
  106.                     x=turtle.down()
  107.                 else
  108.                     return false
  109.                 end
  110.             else
  111.                 turtle.attackDown()
  112.                 x = turtle.down()
  113.             end
  114.         end
  115.     end
  116.     return true
  117. end
  118.  
  119. function turtleForward()
  120.     x = turtle.forward()
  121.     while x == false do
  122.         if turtle.dig() then
  123.         x = turtle.forward()
  124.         else
  125.             if turtle.inspect() then
  126.                 if turtle.dig() then
  127.                     x=turtle.forward()
  128.                 else
  129.                     return false
  130.                 end
  131.             else
  132.                 turtle.attack()
  133.                 x = turtle.forward()
  134.             end
  135.         end
  136.     end
  137.     return true
  138. end
  139.  
  140. function check()
  141.     --Check down first, dig if necessary
  142.     local success, data = turtle.inspectDown()
  143.     if success then
  144.         if checkJunk(data.name) then
  145.             if data.name == "minecraft:flowing_lava" then
  146.                 turtle.select(1)
  147.                 turtle.placeDown()
  148.                 turtle.refuel()
  149.             else
  150.                 turtle.digDown()
  151.             end
  152.         end
  153.     end
  154.     --Check up second, ...
  155.     local success, data = turtle.inspectUp()
  156.     if success then
  157.         if checkJunk(data.name) then
  158.             if data.name == "minecraft:flowing_lava" then
  159.                 turtle.select(1)
  160.                 turtle.placeUp()
  161.                 turtle.refuel()
  162.             else
  163.                 turtle.digUp()
  164.             end
  165.         end
  166.     end
  167. end
  168.  
  169. function inventoryClear()
  170.     for i=1, 16 do
  171.         turtle.select(i)
  172.     local data = turtle.getItemDetail()
  173.         if data then
  174.             if checkJunk(data.name) == false then
  175.                 turtle.drop()
  176.         end
  177.         end
  178.     end
  179.     turtle.select(1)
  180. end
  181.  
  182. function inventoryFull()
  183.     local count = 0
  184.     for i = 1,16 do
  185.         if turtle.getItemCount(i) > 0 then
  186.             count = count + 1
  187.         end
  188.     end
  189.     if count > 10 then
  190.         return true
  191.     else
  192.         return false
  193.     end
  194. end
  195.  
  196. function inventoryUnload()
  197.     for i = 2, 16 do
  198.         turtle.select(i)
  199.         turtle.dropUp()
  200.     end
  201. end
  202.  
  203. --************
  204. --Main Loop
  205. --************
  206.  
  207. ----Fuel
  208. turtle.select(1)
  209. turtle.refuel()
  210. turtle.select(2)
  211. turtle.refuel()
  212. print(turtle.getFuelLevel())
  213.  
  214. ----Descend to bottom (bedrock +5)
  215. while turtleDown() do
  216.     currY = currY - 1
  217. end
  218.  
  219. print(currY)
  220.  
  221. --Move up to avoid non-flat bedrock
  222.  
  223. --for i = 1, 4 do
  224. --  turtleUp()
  225. --  currY = currY + 1
  226. --end
  227.  
  228.  
  229. --Mining Loop
  230. inventoryClear()
  231. while currY < -2 do  --While you are in an acceptable mining range
  232.    
  233.    
  234.    
  235.     for i = 1, width do     --Mine one leg
  236.         turtleForward()
  237.         check()
  238.     end
  239.    
  240.     inventoryClear()
  241.     turtle.turnRight()      --Move right one
  242.     turtleForward()
  243.     currX = currX + 1
  244.     check()
  245.     turtle.turnRight()
  246.    
  247.     for i = 1, width do     --Mine return leg
  248.         turtleForward()
  249.         check()
  250.     end
  251.    
  252.     if currX < width then   --Move left one, or return to 0,0 if complete
  253.         inventoryClear()
  254.         turtle.turnLeft()
  255.         turtleForward()
  256.         currX = currX + 1
  257.         check()
  258.         turtle.turnLeft()
  259.     else
  260.         turtle.turnRight()
  261.         repeat
  262.         turtleForward()
  263.         currX = currX - 1
  264.         until currX == 0
  265.         turtle.turnRight()
  266.        
  267.         for i = 1, 3 do     --Move up three levels
  268.             turtleUp()
  269.             currY = currY + 1
  270.         end
  271.        
  272.         inventoryClear()    --Dump junk
  273.         if inventoryFull() then     --Return to starting level and empty cargo is necessary
  274.             y = currY
  275.             print(y)
  276.             print(turtle.getFuelLevel())
  277.             while currY < 0 do
  278.                 turtleUp()
  279.                 currY = currY + 1
  280.             end
  281.             inventoryUnload()
  282.             while currY > y do
  283.                 turtleDown()
  284.                 currY = currY - 1
  285.             end
  286.         end
  287.     end
  288. end
  289.  
  290. inventoryClear()    --Dump junk
  291. while currY < 0 do
  292.     turtleUp()
  293.     currY = currY + 1
  294. end
  295. inventoryUnload()
  296. --************
  297. --Rev history
  298. --************
  299. --  v0.1 - initial posting
  300. --  v0.2 - fixed MANY issues, added inital fueling from slot2, increased inventoryClear frequency, added junk items, etc, etc, etc,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement