brensen11

dig50x50x3

Mar 18th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.69 KB | None | 0 0
  1. local length = 10 -- x
  2. local width = 10 -- y
  3. local height = 3 -- z
  4. local key1 = false
  5. local key2 = false
  6. local key3 = false
  7. local chestName = "minecraft:ender_chest"
  8. --"enderstorage:ender_storage"
  9.  
  10. local slotCount = 16
  11.  
  12. --Sets the dimensions for the Mining Area from command line arguments
  13. -- Default size is listed above
  14. function SetDimensions(...)
  15.     local args = {...}
  16.     if(#args == 3) then
  17.         length = tonumber(args[1])
  18.         width = tonumber(args[2])
  19.         if(tonumber(args[3]) > 1) then
  20.             height = tonumber(args[3])
  21.         else
  22.             print("minimum height is 2, for walkability reasons, setting height = 3")
  23.         end
  24.     else
  25.         print("Malformed input given, please input using the format: 'Command' 'x' 'y' 'z' ")
  26.         print("Defaulting to 10x10x3")
  27.     end
  28. end
  29.  
  30. SetDimensions(...)
  31.  
  32. --Checks fuel level and refules if fuel level is less than 10
  33. --refuels by checking each slot for fuel
  34. function CheckFuel()
  35.     if(turtle.getFuelLevel() < 10) then
  36.         for slot = 1, slotCount do
  37.             print("Attempting to refuel on slot " .. slot)
  38.             turtle.select(slot)
  39.             if(turtle.refuel(1)) then
  40.                 return true
  41.              end
  42.         end
  43.         return false
  44.     end
  45.     return true
  46. end
  47.  
  48. --Checks each inv slot for enderchest
  49. --returns ender chest slot number
  50. function GetEnderIndex()
  51.     print("Searching for chest")
  52.     for slot = 1, slotCount do
  53.         local item = turtle.getItemDetail(slot)
  54.         if(item ~= nil) then
  55.             if(item["name"] == chestName) then
  56.                 return slot
  57.             end
  58.         end
  59.     end
  60.     return nil
  61. end
  62.  
  63. --Checks if all inventory slots are full
  64. --if full returns true
  65. function InvFullCheck()
  66.     print("Checking if Inventory Full")
  67.     local sum = 0
  68.     for slot = 1, slotCount do
  69.         if(turtle.getItemCount(slot) > 0) then
  70.             sum = sum + 1
  71.         end
  72.     end
  73.     if (sum == slotCount) then
  74.         return true
  75.     end
  76.     return false
  77. end
  78.  
  79. --Dumps all items but coal into an enderchest its carrying
  80. function DumpItems()
  81.     print("Attempting to dump items")
  82.     turtle.select(GetEnderIndex())
  83.     turtle.digUp()
  84.     turtle.placeUp()
  85.     print("Dumping Items")
  86.     for slot = 1, slotCount do
  87.         if(turtle.getItemDetail(slot) ~= nil) then
  88.             local item = turtle.getItemDetail(slot)
  89.            
  90.             if(item["name"] ~= "minecraft:coal") then
  91.                 turtle.select(slot)
  92.                 turtle.dropUp()
  93.             end
  94.         end
  95.     end
  96.     turtle.digUp()
  97. end
  98.  
  99. --For cases of gravel
  100. function DetectAndDig()
  101.     while(turtle.detect()) do
  102.         turtle.dig()
  103.     end
  104. end
  105.  
  106. function Forward()
  107.     DetectAndDig()
  108.     turtle.forward()
  109. end
  110.  
  111. function OneLayer()
  112.     Forward()
  113. end
  114.  
  115. function TwoLayers()
  116.     Forward()
  117.     turtle.digDown()
  118. end
  119.  
  120. function ThreeLayers()
  121.     TwoLayers()
  122.     turtle.digUp()
  123. end
  124.  
  125. function Up()
  126.     while(turtle.detectUp) do
  127.         turtle.digUp()
  128.     end
  129.     turtle.up()
  130. end
  131.  
  132. function turnRight()
  133.     turtle.turnRight()
  134.     Forward()
  135.     turtle.turnRight()
  136. end
  137.  
  138. function turnLeft()
  139.     turtle.turnLeft()
  140.     Forward()
  141.     turtle.turnLeft()
  142. end
  143.  
  144. --Calculates the number of Up()s taken based on the turtles position always being between
  145. --base and last layer of a 3 layer square, (i.e. 2, in 1-3) by checking if z index is less than layer index
  146. --then calculates number of times the turtle needs to go Up by comparing
  147. function CalculateUp(z)
  148.     if(z < height - 2) then
  149.         if((z + 3) == height) then
  150.             Up()
  151.             Up()
  152.         elseif((z + 3) < height) then
  153.             Up()
  154.             Up()
  155.             Up()
  156.         end
  157.     end
  158. end
  159.  
  160. function SetKey(z)
  161.     if(z == height) then
  162.         key1 = true
  163.         key2 = false
  164.         key3 = false
  165.     elseif(height - z == 1) then
  166.         key2 = true
  167.  
  168.         key1 = false
  169.         key3 = false
  170.     else
  171.         key3 = true
  172.  
  173.         key1 = false
  174.         key2 = false
  175.     end
  176. end
  177.  
  178. function TurnAround()
  179.     turtle.turnRight()
  180.     turtle.turnRight()
  181. end
  182.    
  183. --Checks to see if has ender chest and coal
  184. function ReadyForJourney()
  185.     return true
  186. end
  187.  
  188.  
  189. --------------Main----------------------
  190. function Main()
  191. if (not ReadyForJourney()) then
  192. print("Your turtle isnt ready to journey out!")
  193. print("Make sure your turtle has enough fuel and an enderchest!")
  194. return
  195. end
  196.  
  197. for z = 1, height, 3 do                             --
  198.  
  199.     SetKey(z)
  200.  
  201.     for y = 1, width do                         --starting length cuts one turn off
  202.  
  203.         for x = 1, length - 1 do                    --width cuts one length down off the next
  204.             if(not CheckFuel()) then
  205.                 print("Your turtle is out of fuel!")
  206.                 print("Powering down....")
  207.                 return
  208.             end
  209.            
  210.             if(InvFullCheck == true) then
  211.                 DumpItems()
  212.             end
  213.  
  214.             if(key1)then
  215.                 OneLayer()
  216.             elseif(key2)then
  217.                 TwoLayers()
  218.             elseif(key3)then
  219.                 ThreeLayers()
  220.             end
  221.             --run some function with some local variable as a param, that gets changed every z changed
  222.             --based on the number the function will run the right, function of mine one two or three layers
  223.             --somehow WITHOUT doing checks (because if it does checks, its redundancy)
  224.  
  225.         end
  226.  
  227.         if(y ~= 3) then
  228.             if(math.fmod(y, 2) == 0) then
  229.                 turnLeft()
  230.             else
  231.                 turnRight()
  232.             end
  233.         else
  234.             TurnAround()
  235.         end
  236.  
  237.     end
  238.  
  239.     CalculateUp(z)
  240.  
  241. end
  242. end
  243.  
  244. Main()
  245.  
Add Comment
Please, Sign In to add comment