Advertisement
Riewest14

Mining Lib 1.1

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