Advertisement
cing5000

quarry

Apr 8th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.94 KB | None | 0 0
  1. --Ore mining quarry with enderchest
  2. --Made by: Cing
  3. --also blocks off lava
  4. --and sucks items out of a chest
  5.  
  6. local turns = 0
  7. local size = 0
  8. local layers = 0
  9. local y = 0
  10. local place = 0
  11. local eNeeded = 0
  12. local home = 0
  13.  
  14. local notItems = {
  15.   "minecraft:dirt",
  16.   "minecraft:stone",
  17.   "minecraft:gravel",
  18.   "minecraft:chest",
  19.   "minecraft:flowing_lava"
  20.     }
  21.  
  22. function compDown()
  23. local succes, data = turtle.inspectDown()
  24.  if succes then
  25.   if data.name == notItems[1] then
  26.     elseif data.name == notItems[2] then
  27.       elseif data.name == notItems[3] then  
  28.         elseif data.name == notItems[4] then
  29.           for i = 1, 27 do
  30.             turtle.suckDown()
  31.           end
  32.           turtle.digDown()
  33.             elseif data.name == notItems[5] then
  34.               turtle.select(15)
  35.               turtle.placeDown()
  36.             else
  37.           turtle.digDown()      
  38.       end
  39.    end
  40. end
  41.  
  42. function compUp()
  43. local succes, data = turtle.inspectUp()
  44.   if succes then
  45.     if data.name == notItems[1] then
  46.       elseif data.name == notItems[2] then
  47.         elseif data.name == notItems[3] then
  48.           elseif data.name == notItems[4] then
  49.             for i = 1, 27 do
  50.               turtle.suckUp()
  51.             end
  52.             turtle.digUp()
  53.             elseif data.name== notItems[5] then
  54.               turtle.select(15)
  55.               turtle.placeUp()
  56.           else
  57.           turtle.digUp()    
  58.        end    
  59.     end
  60. end
  61.  
  62. function compare()
  63.   compDown()
  64.   compUp()  
  65. end
  66.  
  67. function moveForward()
  68. local succes, data = turtle.inspect()
  69.   while not turtle.forward() do
  70.     if succes then
  71.       if data.name == notItems[4] then
  72.         for i = 1, 27 do
  73.           turtle.suck()
  74.         end
  75.         turtle.dig()
  76.         else  
  77.           turtle.dig()
  78.        end
  79.     end  
  80.   end
  81. end
  82.  
  83. function moveDown()
  84.   while not turtle.down() do
  85.     turtle.digDown()
  86.   end
  87.  y = y-1
  88. end
  89.  
  90. function moveUp()
  91.   while not turtle.up() do
  92.     turtle.digUp()
  93.   end
  94.  y = y+1
  95. end
  96.  
  97. function goHome()
  98.   if layers == 1 and place == 0 then
  99.   else
  100.     repeat
  101.       moveUp()
  102.     until y == home
  103.   end
  104.   if layers == 0 then
  105.     if size%2 == 1 then
  106.       if turns == 0 then
  107.         for i = 1, 2 do
  108.           turtle.turnLeft()
  109.           for i = 1, size-1 do
  110.             moveForward()
  111.           end
  112.         end
  113.       end
  114.     else
  115.       if turns == 1 then
  116.         turtle.turnRight()
  117.         for i = 1, size-1 do
  118.           moveForward()
  119.         end
  120.       end
  121.     end
  122.   elseif layers%2 == 1 then
  123.     if size%2 == 1 then
  124.       for i = 1, 2 do
  125.         turtle.turnLeft()
  126.         for i = 1, size-1 do
  127.           moveForward()
  128.         end    
  129.       end
  130.     else
  131.       turtle.turnRight()
  132.       for i = 1, size-1 do
  133.         moveForward()
  134.       end
  135.     end
  136.   else
  137.     turtle.turnLeft()
  138.   end
  139. end
  140.  
  141. function fuel()
  142.   turtle.select(1)
  143.   if turtle.getFuelLevel() < 50 then
  144.     turtle.refuel()
  145.   end
  146. end
  147.  
  148. function dropItems()
  149. turtle.turnRight()
  150. turtle.turnRight()
  151. local number = 2
  152.   fuel()
  153.   turtle.select(16)
  154.   while not turtle.place() do
  155.     turtle.dig()
  156.   end  
  157.   for i = 1, 13 do
  158.     turtle.select(number)
  159.     turtle.drop()
  160.     number = number+1
  161.   end
  162.   turtle.select(16)
  163.   turtle.dig()
  164.   turtle.select(1)
  165.   turtle.turnRight()
  166.   turtle.turnRight()
  167. end
  168.  
  169. function checkItems()
  170.   if turtle.getItemDetail(11) == false then
  171.   else
  172.     dropItems()
  173.   end
  174. end
  175.  
  176. function dig()
  177.   fuel()  
  178.   compare()  
  179.   for i = 1, size-1 do
  180.     moveForward()
  181.     compare()
  182.   end
  183. end
  184.  
  185. function turnright()
  186.   turtle.turnRight()
  187.   moveForward()
  188.   turtle.turnRight()
  189. end
  190.  
  191. function turnleft()
  192.   turtle.turnLeft()
  193.   moveForward()
  194.   turtle.turnLeft()
  195. end
  196.  
  197. function nextLayer()
  198.   for i = 1,3 do
  199.     moveDown()
  200.   end
  201.   turtle.turnRight()
  202.   turtle.turnRight()
  203. end
  204.  
  205. function square()
  206. local count = 1
  207.   for i = 1, size do
  208.     dig()
  209.     if count ~= size then
  210.       if turns == 0 then
  211.         turnright()
  212.         turns = 1
  213.       else
  214.         turnleft()
  215.         turns = 0
  216.       end
  217.       count = count+1
  218.     end
  219.   end
  220.   if turns == 0 then
  221.     checkItems()
  222.   end
  223. end
  224.  
  225. function Layers()
  226.   square()
  227.   if layers > 1 then
  228.     for i = 1, layers-1 do
  229.       nextLayer()
  230.       square()
  231.     end
  232.   end
  233. end
  234.  
  235. function Bedrock()
  236.   square()
  237.   repeat
  238.     if y == 3 then
  239.       moveDown()
  240.       turtle.turnRight()
  241.       turtle.turnRight()
  242.       square()
  243.     else
  244.       nextLayer()
  245.       square()
  246.     end
  247.   until y < 3
  248. end  
  249.  
  250. function getInPlace()
  251.   if place == 1 then
  252.     for i = 1, 3 do
  253.       moveDown()
  254.     end
  255.   elseif place == 0 then
  256.     moveForward()
  257.   else
  258.     print("Place must be 1 or 0")
  259.     print("Please try again")
  260.     sleep(3)
  261.     os.reboot()
  262.   end
  263. end
  264.  
  265. function calcEnergy()
  266.   if layers == 0 then
  267.     eNeeded = ((size*size*(y/3))+50)
  268.   else
  269.     eNeeded = ((size*size*layers)+50)
  270.   end
  271. end
  272.  
  273. print("---------------------------------------")
  274. print("Advanced ore mining quarry")
  275. print("Made by: Cing")
  276. print("---------------------------------------")
  277.  
  278. print("Please put first coal in slot 1...")
  279. print("some filling blocks in slot 15...")
  280. print("and a enderchest in slot 16.")
  281. print("And don't forget to chunkload the area.")
  282. os.pullEvent()
  283.  
  284. write("What is the YLevel: ")
  285. y = tonumber(read())
  286. home = y
  287.  
  288. print("Are you above or under ground: ")
  289. write("Type 1 for above and 0 for under: ")
  290. place = tonumber(read())
  291.  
  292. write("What size do you want: ")
  293. size = tonumber(read())
  294.  
  295. print("How many layers do you want?")
  296. write("Or type 0 to go to bedrock: ")
  297. layers = tonumber(read())
  298.  
  299. print(y)
  300. calcEnergy()
  301. repeat
  302.   if eNeeded < turtle.getFuelLevel() then
  303.   else
  304.     turtle.refuel()
  305.     print("Please put more coal in slot 1")
  306.     os.pullEvent()
  307.   end
  308. until eNeeded < turtle.getFuelLevel()
  309.  
  310. getInPlace()
  311. term.clear()
  312. term.setCursorPos(1, 1)
  313. print("Digging")
  314.  
  315. if layers == 0 then
  316.   Bedrock()
  317.   else
  318.   Layers()
  319. end
  320.  
  321. print("Done!!!")
  322. goHome()
  323. dropItems()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement