Advertisement
Birog

Mining_v3

Feb 25th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.57 KB | None | 0 0
  1. local function setFacingAngle(FacingAngle, WishedFacingAngle)
  2.   if FacingAngle < WishedFacingAngle then
  3.     for DiffFacingAngle = 1, (WishedFacingAngle - FacingAngle) do
  4.       turtle.turnRight()
  5.       FacingAngle = FacingAngle + 1
  6.     end
  7.   elseif FacingAngle > WishedFacingAngle then
  8.     for DiffFacingAngle = 1, (FacingAngle - WishedFacingAngle) do
  9.       turtle.turnLeft()
  10.       FacingAngle = FacingAngle - 1
  11.     end  
  12.   end
  13.   return FacingAngle
  14. end
  15.  
  16. local function refuel(coal_slot)
  17.   turtle.select(coal_slot)
  18.   boolRefuel = turtle.refuel(1)
  19.   if boolRefuel then
  20.     refuel_count = 0
  21.     print("Successfully Refueled")
  22.   else
  23.     print("Out of fuel")
  24.     while not(turtle.refuel(1)) do
  25.       setFacingAngle(FacingAngle, FacingAngle + 2)
  26.       setFacingAngle(FacingAngle, FacingAngle - 2)
  27.     end    
  28.   end
  29.   turtle.select(1)  
  30.   return refuel_count  
  31. end
  32.  
  33. local function moveForward(done_lenght, BoolIncreasingLenght, FacingAngle, Boolfb, moving_integer, digUpBool, refuel_count)
  34. local moving_count = 1
  35.   for moving_count=1,moving_integer do
  36.     if (refuel_count == 80) then
  37.       refuel_count = refuel(2)
  38.     end
  39.     Bool1 = false
  40.     while not(Bool1) do
  41.       if (Boolfb) then
  42.         turtle.dig()
  43.         Bool1 = turtle.forward()
  44.         if (digUpBool) then
  45.           turtle.digUp()
  46.         end
  47.       else
  48.         Bool1 = turtle.back()
  49.         if not(Bool1) then
  50.           setFacingAngle(FacingAngle, (FacingAngle + 2))
  51.           turtle.dig()
  52.           setFacingAngle(FacingAngle, (FacingAngle - 2))
  53.         end
  54.       end    
  55.     end
  56.     moving_count = moving_count + 1
  57.     refuel_count = refuel_count + 1
  58.     if BoolIncreasingLenght then
  59.       done_lenght = done_lenght + 1
  60.     end  
  61.   end
  62. return done_lenght, refuel_count  
  63. end
  64.  
  65. local function moveUp(YPosition, Boolud, moving_integer, refuel_count)
  66. local moving_count = 1
  67.   for moving_count=1,moving_integer do
  68.     if (refuel_count == 80) then
  69.       refuel_count = refuel(2)
  70.     end
  71.     Bool2 = false
  72.     while not(Bool2) do
  73.       if (Boolud) then
  74.         turtle.digUp()   
  75.         Bool2 = turtle.up()
  76.       else
  77.         turtle.digDown()
  78.         Bool2 = turtle.down()
  79.       end
  80.     end
  81.     moving_count = moving_count + 1
  82.     if (Boolud) then
  83.       YPosition = YPosition + 1
  84.     else
  85.       YPosition = YPosition - 1
  86.     end
  87.     refuel_count = refuel_count + 1
  88.   end
  89. return YPosition, refuel_count
  90. end
  91.  
  92. local function inventoryManagement(saved_slots,refuel_count)
  93.   turtle.select(1)
  94.   n = saved_slots + 1
  95.  
  96.   repeat
  97.     item_count = turtle.getItemCount(n)
  98.     if (item_count ~= 0) then      
  99.       boolSlotOccupied = true
  100.       n = n + 1  
  101.     else
  102.       boolSlotOccupied = false  
  103.     end  
  104.   until (boolSlotOccupied == false) or (n == 17)
  105.   if (n == 17) then
  106.     print("Inventory full")
  107.     FacingAngle = setFacingAngle(FacingAngle, (FacingAngle - 1))
  108.     done_lenght , refuel_count = moveForward(done_lenght, false, FacingAngle, true, 1, true, refuel_count)
  109.     done_lenght , refuel_count = moveForward(done_lenght, false, FacingAngle, false, 1, false, refuel_count)
  110.     turtle.select(3)
  111.     turtle.place()
  112.     for u=(saved_slots+1),16 do
  113.       turtle.select(u)
  114.       turtle.drop()
  115.     end
  116.     turtle.select(1)
  117.     FacingAngle = setFacingAngle(FacingAngle, (FacingAngle + 1))
  118.   else
  119.     print("Inventory OK")
  120.   end
  121.   return refuel_count  
  122. end
  123.  
  124. YPosition = 10
  125. FacingAngle = 2
  126. coal_slot = 2
  127. print("Please place torches in the first slot, coal in the second one and chests in the third one")
  128. print("How many parallel tunnels are you willing to dig ?")
  129. tunnels_integer = read()
  130. print("How long do you want each tunnel to be ?")
  131. tunnels_lenght = read()
  132. print("How many blocks do you want between two tunnels ?")
  133. tunnels_separation = read()
  134. local a = 1
  135. local i=1
  136. local refuel_count = 0
  137. refuel(2)
  138. YPosition, refuel_count = moveUp(YPosition, true, 1, refuel_count)
  139. for a=1,tunnels_integer do
  140. done_lenght = 0
  141. for i=1,(tunnels_lenght-done_lenght) do
  142.   done_lenght, refuel_count = moveForward(done_lenght, true, FacingAngle, true, 1, true, refuel_count)
  143.   turtle.digDown()
  144.   if (0 == i%10) then
  145.     turtle.turnRight()
  146.     turtle.dig()
  147.     turtle.place()
  148.     turtle.turnLeft()
  149.   end
  150.   refuel_count = inventoryManagement(3,refuel_count)
  151.  
  152.   print("Momentum left before refueling: "..(80-refuel_count))
  153. end
  154.   done_lenght, refuel_count = moveForward(done_lenght, false, FacingAngle, false, tunnels_lenght, true, refuel_count)
  155.   FacingAngle = setFacingAngle(FacingAngle, (FacingAngle - 1))
  156.   done_lenght, refuel_count = moveForward(done_lenght, false, FacingAngle, true, (tunnels_separation+1), false, refuel_count)
  157.   FacingAngle = setFacingAngle(FacingAngle, (FacingAngle + 1))
  158.   a = a + 1
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement