Riewest14

miningLIB

Apr 27th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----------------
  2. --Name: miningLIB
  3. --Version: 1.0.0
  4. --Requires: riewestLIB
  5. --By: Riewest (AKA Riewest14)
  6. -----------------
  7.  
  8. os.loadAPI("riewestLIB")
  9. lib = riewestLIB
  10.  
  11. --junk item array
  12. junkItems = {"stone", "gravel", "dirt", "sand"}
  13.  
  14. function test()
  15.   --strip(10, true, false, 15)
  16.   branchMine(10, 2, 2, true, 16, 15, true)
  17.   --lib.turnAround()
  18.   --dropJunk()
  19. end
  20.  
  21. --Veinmine the block in front
  22. --Returning to the starting position
  23. function veinMine()
  24.   --TODO
  25. end
  26.  
  27. --Does a branch mine
  28. --Length: length of the mine
  29. --spaceBet: space between branches
  30. --branchLength: length of branches
  31. --retStart: returns to start if true
  32. --chestSlot: if not nil will dump items
  33. --            into that chest
  34. --fuelSlot: slot to attempt refueling
  35. --          from if not nil
  36.  
  37. function branchMine(length, spaceBet, branchLength, retStart, fuelSlot, chestSlot, dropjunk)
  38.   if not length then
  39.     length = 15
  40.   end
  41.   if not spaceBet then
  42.     spaceBet = 1
  43.   end
  44.   if not branchLength then
  45.     branchLength = 5
  46.   end
  47.   if not retStart then
  48.     retStart = false
  49.   end
  50.   if not fuelSlot then
  51.     fuelSlot = false
  52.   end
  53.   if not chestSlot then
  54.     chestSlot = false
  55.   end
  56.   local count = 0
  57.   local lengthLeft = length
  58.   for i = 1, length do
  59.     if count > 100 then
  60.       count = 0
  61.     end
  62.     if lengthLeft < spaceBet then
  63.       strip(lengthLeft, false, fuelSlot, chestSlot)
  64.       break
  65.     end
  66.     local moved = strip(spaceBet + 1, false, fuelSlot, chestSlot)
  67.     i = i + moved
  68.     count = count + math.fmod(moved, 100)
  69.     lengthLeft = lengthLeft - moved
  70.     turtle.turnLeft()
  71.     local s1 = strip(branchLength, true, fuelSlot, false)
  72.     local s2 = strip(branchLength, true, fuelSlot, false)
  73.     count = count + (math.fmod(s1, 100) + math.fmod(s2, 100))
  74.     print("Count: " .. count)
  75.     doChestG(chestSlot, count, 100, fuelSlot, dropjunk)
  76.     turtle.turnRight()
  77.   end
  78.   if retStart then
  79.     lib.turnAround()
  80.     lib.tMoveF(length)
  81.   end
  82. end
  83.  
  84. --Drops junk items
  85. function dropJunk(fuelSlot, chestSlot)
  86.   local slotsToKeep = {}
  87.   if fuelSlot then
  88.     table.insert(fuelSlot)
  89.   end
  90.   if chestSlot then
  91.     table.insert(chestSlot)
  92.   end
  93.   for k, v in pairs(junkItems) do
  94.     lib.dropItem(v, slotsToKeep, "bottom")
  95.   end
  96. end
  97.  
  98. --Method to check if chest should be
  99. --placed above and empty the inventory
  100. --chestSlot: slot the chest is in if nil
  101. --           will not empty inventory
  102. --dist: Distance the turtle has traveled
  103. --interval: interval inventory should
  104. --          be checked
  105. --fuelSlot: optional fuelslot
  106. --dropjunk: drops the junk items
  107. function doChest(chestSlot, dist, interval, fuelSlot, dropjunk)
  108.   if chestSlot and (math.fmod(dist, interval) == 0) and (turtle.getItemCount(chestSlot) > 0 ) then
  109.     local oldSlot = turtle.getSelectedSlot()
  110.     turtle.select(chestSlot)
  111.     local chestData = turtle.getItemDetail()
  112.     lib.tMoveU()
  113.     turtle.digUp()
  114.     lib.tMoveD()
  115.     while not turtle.placeUp() do
  116.       turtle.digUp()
  117.       sleep(.1)
  118.     end
  119.     local slotsToKeep = {chestSlot}
  120.     if fuelSlot then
  121.       lib.sortItem(fuelSlot)
  122.       table.insert(slotsToKeep, fuelSlot)
  123.     end
  124.     if dropjunk then
  125.       dropJunk()
  126.     end
  127.     lib.emptyInvExcept(slotsToKeep, "top")
  128.     turtle.select(chestSlot)
  129.     if not (chestData.name == "minecraft:chest") then
  130.       while not turtle.digUp() do
  131.         sleep(.1)
  132.       end
  133.     end
  134.     turtle.select(oldSlot)
  135.   end
  136. end
  137.  
  138. --Slight variation on do chest where
  139. -- it does the function if blocks
  140. -- moved is greater than chest interval
  141. -- takes same parameters
  142. function doChestG(chestSlot, dist, interval, fuelSlot, dropjunk)
  143.   if not chestSlot then
  144.     return
  145.   end
  146.   if dist > interval then
  147.     dist = interval
  148.   end
  149.   doChest(chestSlot, dist, interval, fuelSlot, dropjunk)
  150. end
  151.  
  152. --Mine a 1b wide 3b tall tunnel
  153. --for length passed. Returns to
  154. -- the start if retStart is true
  155. -- chestSlot: if not nil will dump items
  156. --             into that chest
  157. -- fuelSlot: if not nill will refuel from
  158. --            that slot.
  159. function strip(length, retStart, fuelSlot, chestSlot, dropjunk)
  160.   if not length then
  161.     length = 5
  162.   end
  163.   if not retStart then
  164.     retStart = false  
  165.   end
  166.   if not chestSlot then
  167.     chestSlot = false
  168.   end
  169.   if not fuelSlot then
  170.     fuelSlot = false
  171.   end
  172.  
  173.   for i = 1, length do
  174.     lib.tMoveF()
  175.     turtle.digUp()
  176.     turtle.digDown()
  177.     if fuelSlot then
  178.       lib.tRefuel(fuelSlot)
  179.     end
  180.     doChest(chestSlot, i, 100, fuelSlot, dropjunk)
  181.   end
  182.   if retStart then
  183.     lib.turnAround()
  184.     lib.tMoveF(length)
  185.   end
  186.   return length
  187. end
  188.  
  189.  
  190.  
  191.  
  192. test()
Add Comment
Please, Sign In to add comment