View difference between Paste ID: YinWvmsj and 8gjWpDcc
SHOW: | | - or go back to the newest paste.
1
local tArgs = { ... }
2
3
local digDownAmount
4
local digDeepAmount
5
local stripeAmount
6
7
local chestSlot = 2
8
9
if not (#tArgs == 3) then
10
  print ("You need exactly three parameter!")
11
  return
12
else
13
  digDownAmount = tonumber(tArgs[1])
14
  digDeepAmount = tonumber(tArgs[2])
15
  stripeAmount = tonumber(tArgs[3])
16
end 
17
18
local function mineToBase(amount)
19
  turtle.select(1)
20
  for i = 1, amount do
21
    while not turtle.down() do
22
	turtle.digDown()
23
    end
24
    turtle.placeUp()
25
  end
26
end
27
28
local function moveToTop(amount)
29
  turtle.select(1)
30
  for i = 1, amount do
31
    while not turtle.up() do
32
	turtle.digUp()
33
    end
34
    turtle.placeDown()
35
  end
36
end
37
38
local function PlaceChest()
39
  print ("PlaceChest called...")
40
  turtle.select(chestSlot)
41
  while true do
42
    if (turtle.getItemCount(chestSlot) == 1) and (turtle.place()) or (turtle.dig() and turtle.place()) then
43
      print("Chest successfully placed!")
44
      break
45
    else
46
      print("Chest placing error!")
47
      sleep(1)
48
    end      
49
  end
50
  turtle.turnRight()
51
  turtle.turnRight()
52
end
53
54
local function DigRow()
55
  turtle.dig()
56
  while not turtle.forward() do
57
    sleep(1)
58
  end
59
  turtle.digDown()
60
  turtle.digUp()      
61
end
62
63
local function EmptyInventory()
64
  for i = 1, 16 do
65
    turtle.select(i)
66
    turtle.drop()
67
  end
68
end
69
70
local function FirstMining(amount)
71
  for i = 1, amount do
72
    DigRow()
73
  end
74
  
75
  turtle.turnLeft()
76
  turtle.turnLeft()
77
  for i = 1, amount do
78
    while not turtle.forward() do
79
    if turtle.dig() then
80
      turtle.forward()
81
      break
82
    end
83
    sleep(1)
84
    end
85
  end
86
  
87
  EmptyInventory()
88
  
89
  turtle.turnLeft()
90
  turtle.turnLeft()
91
end
92
93
local function PickUpEnderChest()
94
  turtle.select(chestSlot)
95
  local turns = 0
96
    while true do
97
    if turtle.detect() then
98
      turtle.dig()
99
      break
100
    end
101
    turtle.turnRight()
102
    turns = turns + 1
103
    if (turns == 4) then
104
      turns = 0
105
      print("No chest detected.. waiting")
106
      sleep(5)
107
    end    
108
  end  
109
end
110
111
local function PlaceEnderChest()
112
  turtle.select(chestSlot)
113
  while true do
114
    if not turtle.place() then
115
      print("Cannot place chest for ending, waiting...")
116
      sleep(5)
117
    else
118
      break
119
    end
120
  end
121
end
122
123
local function GetChest()
124
  turtle.turnLeft()
125
  turtle.turnLeft()
126
  turtle.select(chestSlot)
127
  turtle.dig()
128
end
129
130
local function MiningLoop(amount)
131
  for i = 1, amount do
132
    PlaceChest()
133
    FirstMining(digDeepAmount)
134
    GetChest()
135
136
    turtle.turnRight()
137
    for i = 1, 2 do
138
        turtle.dig()
139
        turtle.forward()
140
    end
141
    turtle.turnLeft()
142
  end
143
end
144
145
PickUpEnderChest()
146
mineToBase(digDownAmount)
147
MiningLoop(stripeAmount)
148
moveToTop(digDownAmount)
149
PlaceEnderChest()
150
print ("Run successfully!")