Advertisement
Guest User

tsukiMine_v0.4

a guest
Jan 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | None | 0 0
  1. -- Variable decleration.
  2. local cycleCount
  3. local inFront, blockInfo = turtle.inspect()
  4.  
  5. local blocksMoved = 0
  6. local freeSlots
  7. local selectedSlotItemInfo1
  8. local isBlockInFront, blockInfoInFront = turtle.inspect()
  9. local isBlockAbove, blockInfoAbove = turtle.inspectUp()
  10. local isBlockBelow, blockInfoBelow = turtle.inspectDown()
  11.  
  12. -- Functions.
  13. function digSuckMove(direction)
  14.     if direction == "up" then
  15.         if turtle.detectUp() == true then
  16.             print("Block above! Mining, picking up and moving up!")
  17.             turtle.digUp()
  18.             turtle.suckUp()
  19.             turtle.up()
  20.         else
  21.             print("Nothing above! Moving up!")
  22.             turtle.up()
  23.         end
  24.        
  25.     elseif direction == "down" then
  26.         if turtle.detectDown() == true then
  27.             print("Block below! Mining, picking up and moving down!")
  28.             turtle.digDown()
  29.             turtle.suckDown()
  30.             turtle.Down()
  31.         else
  32.             print("Nothing below! Moving down!")
  33.             turtle.Down()
  34.         end
  35.    
  36.     elseif direction == "forward" then
  37.         if turtle.detect() == true then
  38.             print("Block in front! Mining, picking up and moving forward!")
  39.             turtle.dig()
  40.             turtle.suck()
  41.             turtle.forward()
  42.         else
  43.             print("Nothing in front! Moving forward!")
  44.             turtle.forward()
  45.         end
  46.     else
  47.         print("Invalid argument!")
  48.     end
  49. end
  50.  
  51. function returnToStart(wasHalted)  
  52.  local x
  53.  
  54.  turtle.turnLeft()
  55.  turtle.turnLeft()
  56.  
  57.  if wasHalted == true then
  58.    x = blocksMoved
  59.  else
  60.    x = cycleCount
  61.  end
  62.  
  63.  for i3 = 1, x, 1 do
  64.   while turtle.detect() do
  65.     print("Can't move back!")
  66.     os.sleep(1)
  67.   end
  68.   turtle.forward()
  69.   print("Still need to move back "..cycleCount-i3.." times.")
  70.     end
  71.  
  72.  print("Dumping items!")
  73.  
  74.  for i3 = 1, 16, 1 do
  75.   turtle.select(i3)
  76.   turtle.drop()
  77.  end
  78.  
  79.  turtle.turnLeft()
  80.  turtle.turnLeft()
  81. end
  82.  
  83. function isSpaceForItem(directionOfMining)
  84.     -- Is there a free slot available?
  85.     freeSlots = 0
  86.     for i = 1, 16, 1 do
  87.         if turtle.getItemCount(i) == 0 then
  88.             freeSlots = freeSlots + 1
  89.         end
  90.     end
  91.     if freeSlots == 9 or freeSlots > 9 then
  92.         return true
  93.     end
  94.    
  95.     -- Is there space for the same item then?
  96.     if directionOfMining == "forward" then
  97.         for i = 1, 16, 1 do
  98.             selectedSlotItemInfo1 = turtle.getItemDetail(i)
  99.             if blockInfoInFront.name ==  selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
  100.                 return true
  101.             end
  102.         end
  103.     elseif
  104.         directionOfMining == "up" then
  105.         for i = 1, 16, 1 do
  106.             selectedSlotItemInfo1 = turtle.getItemDetail(i)
  107.             if blockInfoAbove.name ==  selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
  108.                 return true
  109.             end
  110.         end
  111.     elseif
  112.         directionOfMining == "down" then
  113.         for i = 1, 16, 1 do
  114.             selectedSlotItemInfo1 = turtle.getItemDetail(i)
  115.             if blockInfoBelow.name ==  selectedSlotItemInfo1.name and turtle.getItemCount(i) < 55 then
  116.                 return true
  117.             end
  118.         end
  119.     else
  120.         -- No space available!
  121.         return false
  122.     end
  123. end
  124.  
  125. -- Main Program.
  126.  
  127. -- Read the cycle count.
  128. print("How many cycles to run?")
  129. cycleCount = read()
  130.  
  131. -- Check if there is space for a maximum yeild of the cycle.
  132. if isSpaceForItem() == true then
  133.  
  134. -- Run the cycle.
  135. for i = 1, cycleCount, 1 do
  136.  
  137.   -- Print the current cycle number.
  138.   print("Running cycle number "..i..".")
  139.  
  140.   digSuckMove("forward")
  141.   blocksMoved = blocksMoved + 1
  142.   digSuckMove("up")
  143.   digSuckMove("up")
  144.   turtle.turnLeft()
  145.  
  146.   for i2 = 1, 2, 1 do
  147.     turtle.dig()
  148.     turtle.down()
  149.   end
  150.   turtle.dig()
  151.  
  152.   turtle.turnRight()
  153.   turtle.turnRight()
  154.  
  155.   for i2 = 1, 2, 1 do
  156.     turtle.dig()
  157.     turtle.up()
  158.   end
  159.   turtle.dig();
  160.  
  161.   turtle.turnLeft()
  162.   turtle.down()
  163.   turtle.down()
  164.  
  165. -- End of for.  
  166. end
  167.  
  168. print("Run completed successfuly! Returning to base!")
  169. returnToStart(false)
  170.  
  171. print("Returned to starting position! Press any button to clear screen!")
  172. os.pullEvent('key')
  173. term.clear()
  174. term.setCursorPos(1,1)
  175. else
  176.   print("Not enough free space for a max cycle yield! Returning to base!")
  177.   returnToStart(true)
  178.  
  179.   print("Returned to starting position! Press any button to clear screen!")
  180.   os.pullEvent('key')
  181.   term.clear()
  182.   term.setCursorPos(1,1)
  183. end
  184. -- Prevent instant termination.
  185. -- read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement