brensen11

2DMine

Mar 26th, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. local length = 10 -- x
  2. local width = 10 -- y
  3. local chestName = "enderstorage:ender_storage"
  4. --"enderstorage:ender_storage"
  5. local slotCount = 16
  6.  
  7. --Sets the dimensions for the Mining Area from command line arguments
  8. -- Default size is listed above
  9. function SetDimensions(...)
  10. local args = {...}
  11. if(#args == 2) then
  12. length = tonumber(args[1])
  13. width = tonumber(args[2])
  14. else
  15. print("Malformed input given, please input using the format: 'Command' 'x' 'y' ")
  16. print("Defaulting to 10x10x3")
  17. end
  18. end
  19.  
  20. SetDimensions(...)
  21.  
  22. --Checks fuel level and refules if fuel level is less than 10
  23. --refuels by checking each slot for fuel
  24. function CheckFuel()
  25. if(turtle.getFuelLevel() < 10) then
  26. for slot = 1, slotCount do
  27. print("Attempting to refuel on slot " .. slot)
  28. turtle.select(slot)
  29. if(turtle.refuel(1)) then
  30. return true
  31. end
  32. end
  33. return false
  34. end
  35. return true
  36. end
  37.  
  38. --Checks each inv slot for enderchest
  39. --returns ender chest slot number
  40. function GetEnderIndex()
  41. print("Searching for chest")
  42. for slot = 1, slotCount do
  43. local item = turtle.getItemDetail(slot)
  44. if(item ~= nil) then
  45. if(item["name"] == chestName) then
  46. return slot
  47. end
  48. end
  49. end
  50. return nil
  51. end
  52.  
  53. --Checks if all inventory slots are full
  54. --if full returns true
  55. function InvFullCheck()
  56. print("Checking if Inventory Full")
  57. local sum = 0
  58. for slot = 1, slotCount do
  59. if(turtle.getItemCount(slot) > 0) then
  60. sum = sum + 1
  61. end
  62. end
  63. if (sum == slotCount) then
  64. return true
  65. end
  66. return false
  67. end
  68.  
  69. --Dumps all items but coal into an enderchest its carrying
  70. function DumpItems()
  71. print("Attempting to dump items")
  72. turtle.select(GetEnderIndex())
  73. turtle.digUp()
  74. turtle.placeUp()
  75. print("Dumping Items")
  76. for slot = 1, slotCount do
  77. if(turtle.getItemDetail(slot) ~= nil) then
  78. local item = turtle.getItemDetail(slot)
  79.  
  80. if(item["name"] ~= "minecraft:coal") then
  81. turtle.select(slot)
  82. turtle.dropUp()
  83. end
  84. end
  85. end
  86. turtle.digUp()
  87. end
  88.  
  89. --For cases of gravel
  90. function DetectAndDig()
  91. while(turtle.detect()) do
  92. turtle.dig()
  93. end
  94. end
  95.  
  96. function Forward()
  97. DetectAndDig()
  98. turtle.forward()
  99. turtle.digUp()
  100. turtle.digDown()
  101. end
  102.  
  103. function turnRight()
  104. turtle.turnRight()
  105. Forward()
  106. turtle.turnRight()
  107. end
  108.  
  109. function turnLeft()
  110. turtle.turnLeft()
  111. Forward()
  112. turtle.turnLeft()
  113. end
  114.  
  115. function TurnAround()
  116. turtle.turnRight()
  117. turtle.turnRight()
  118. end
  119.  
  120. --Checks to see if has ender chest and coal
  121. function ReadyForJourney()
  122. return true
  123. end
  124.  
  125. --------------Main----------------------
  126. function Main()
  127. if (not ReadyForJourney()) then
  128. print("Your turtle isnt ready to journey out!")
  129. print("Make sure your turtle has enough fuel and an enderchest!")
  130. return
  131. end
  132.  
  133. for y = 1, width do --starting length cuts one turn off
  134.  
  135. for x = 1, length - 1 do --width cuts one length down off the next
  136. if(not CheckFuel()) then
  137. print("Your turtle is out of fuel!")
  138. print("Powering down....")
  139. return
  140. end
  141.  
  142. if(InvFullCheck() == true) then
  143. DumpItems()
  144. end
  145.  
  146. Forward()
  147.  
  148.  
  149. end
  150.  
  151. if(width - y ~= 0) then
  152. if(math.fmod(y, 2) == 0) then
  153. turnLeft()
  154. else
  155. turnRight()
  156. end
  157. else
  158. TurnAround()
  159. end
  160.  
  161. end
  162. end
  163.  
  164. Main()
  165.  
Add Comment
Please, Sign In to add comment