• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# ST

Julian1472 Jul 17th, 2019 (edited) 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. local Ores = {Diamond, Coal, Iron, Gold, Emerald}
2. local AmountToMine = 0
3. local MineableBlocks = 0
4. local PMovements = 0
5. local RMovements  = 0
6. local Fueled = false
7. local BlocksMined = 0
8.
9.
10. local function mined(BlocksMined)
11. BlocksMined = BlocksMined + 1
12. return BlocksMined
13. end
14. local function GetMineableBlocks(PMovements)
15. PMovements = turtle.getFuelLevel()
16.     for i = 3,PMovements do
17.         MineableBlocks = MineableBlocks + 1
18.     end
19. return MineableBlocks
20. end
21.
22. local function GetRequiredMovements(AmountToMine)
23.     for i = 1,AmountToMine do
24.         RMovements = RMovements + 3
25.     end
26. return RMovements
27. end
28.
29. local function checkfuel(AmountToMine,MineableBlocks,RMovements,PMovements)
30. turtle.refuel()
31. MineableBlocks = GetMineableBlocks(PMovements)
32.     if turtle.getFuelLevel() <= RMovements then
33.         print("Insert fuel in slot 1. ")
34.         return false
35.     elseif tonumber(AmountToMine) >= MineableBlocks then
36.         print("You may not dig that many blocks!")
37.         return false
38.     else
39.         for i = 1, 16 do -- loop through the slots
40.             turtle.select(i) -- change to the slot
41.                 if turtle.refuel(0) then -- if it's valid fuel
42.                     local halfStack = math.ceil(turtle.getItemCount(i)/2) -- work out half of the amount of fuel in the slot
43.                     turtle.refuel(halfStack) -- consume half the stack as fuel
44.                 end
45.         end
46.         return true
47.     end
48. end
49.
50. local function MINEALG(BlocksMined, AmountToMine)
51. local BlockFS = turtle.detect()-- Block Forward Status.
52. local BlockDS = turtle.detectDown()-- Block Down Status.
53.
54.     for i = 1,AmountToMine do
55.         BlockFS = turtle.detect()
56.         BlockDS = turtle.detectDown()
57.         if BlockFS == true then
58.             BlockDS = turtle.detectDown()
59.             if BlockDS == true then
60.                 turtle.digDown()
61.                 turtle.forward()
62.                 BlocksMined = mined(BlocksMined)
63.             end
64.             turtle.dig() -- Mine forwards.
65.             BlocksMined = mined(BlocksMined)
66.             turtle.forward() -- Move forwards.
67.             if BlockDS == false then
68.                 turtle.forward()-- Move forwards.
69.             else end
70.
71.         elseif BlockFS == false then
72.             while BlockFS == false do
73.                 if BlockDS == true then
74.                     turtle.digDown()
75.                     turtle.forward()
76.                     BlocksMined = mined(BlocksMined)
77.                 else
78.                     turtle.forward() -- Move forwards.
79.                     BlockFS = turtle.detect()
80.                 end
81.             end
82.         end
83.
84.     end
85. return BlocksMined
86. end
87.
88. local function initialize(MineableBlocks,AmountToMine,RMovements,Fueled)
89. MineableBlocks = GetMineableBlocks(PMovements) -- Get the largest possible amount of blocks that could be digd at the current fuel level.
90.
91. print("Mine Length?") -- Self explanatory.
93.
94. RMovements = GetRequiredMovements(AmountToMine) -- Get the required movments for a tunnel of that length.
95. Fueled = checkfuel(AmountToMine,MineableBlocks,RMovements,PMovements) -- Check to see if the current fuel level will satiate your instructions.
96.     if Fueled == true then
97.         MINEALG(BlocksMined,AmountToMine) -- Execute the Mining Algorithm.
98.     else
99.         while Fueled == false do
100.             os.sleep(1)
101.             checkfuel(AmountToMine,MineableBlocks,RMovements) -- Check the fuel level until it is high enough to that the turtle may dig.
102.         end
103.     end
104.
105. end
106.
107. initialize(MineableBlocks,AmountToMine,RMovements,Fueled)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top