View difference between Paste ID: Z5LjQyED and YinWvmsj
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
7+
local fuelSlot = 1
8
9
local stripeIndex = 1
10
local digDeepIndex = 1
11
12
if not (#tArgs == 3) then
13
  print ("You need exactly three parameter!")
14
  return
15
else
16
  digDownAmount = tonumber(tArgs[1])
17
  digDeepAmount = tonumber(tArgs[2])
18
  stripeAmount = tonumber(tArgs[3])
19-
  turtle.select(1)
19+
20
21-
    while not turtle.down() do
21+
local function forward()
22-
	turtle.digDown()
22+
23
    if not turtle.dig() then
24
      turtle.attack()
25
      sleep(0.5)
26
    end
27
  end
28
end
29-
  turtle.select(1)
29+
30
local function up()
31-
    while not turtle.up() do
31+
  while not turtle.up() do
32-
	turtle.digUp()
32+
    if not turtle.digUp() then
33
      turtle.attackUp()
34
      sleep(0.5)
35
    end
36
  end
37
end
38-
local function PlaceChest()
38+
39-
  print ("PlaceChest called...")
39+
local function down()
40-
  turtle.select(chestSlot)
40+
  while not turtle.down() do
41-
  while true do
41+
    if not turtle.digDown() then
42-
    if (turtle.getItemCount(chestSlot) == 1) and (turtle.place()) or (turtle.dig() and turtle.place()) then
42+
      turtle.attackDown()
43-
      print("Chest successfully placed!")
43+
      sleep(0.5)
44
    end
45
  end
46-
      print("Chest placing error!")
46+
47-
      sleep(1)
47+
48-
    end      
48+
local function FindChest()
49
  while not ChestFound do
50
    for i = 1, 4 do
51
      if turtle.detect() then
52
        print("Chest found... starting mine operation!")
53
        return
54
      else
55
        turtle.turnRight()
56
      end
57-
    sleep(1)
57+
58
    print("No Chest found.. place a chest near turtle to start mining")
59
    sleep(3)
60
  end
61
end
62
63
local function mineToBase(amount)
64-
  for i = 1, 16 do
64+
  turtle.select(fuelSlot + 1)
65
  for i = 1, amount do
66
    down()
67
    turtle.placeUp()
68
  end
69
  print("Arrived at mining level.. start mining")
70
end
71
72-
    DigRow()
72+
73
  turtle.select(fuelSlot + 1)
74
  for i = 1, amount do
75
    up()
76
    turtle.placeDown()
77
  end
78-
    while not turtle.forward() do
78+
  print("Arrived at starting level.. empting inventory")
79-
    if turtle.dig() then
79+
80-
      turtle.forward()
80+
81
-- Returns false if inventory full
82
local function ContinueDigging()
83-
    sleep(1)
83+
  -- Check inventory
84
  if (turtle.getItemCount(16) >= 0) then
85
    return false
86
  end
87-
  EmptyInventory()
87+
88
89
local function DigRow()
90
  turtle.dig()
91
  forward()
92
  turtle.digDown()
93-
local function PickUpEnderChest()
93+
94-
  turtle.select(chestSlot)
94+
95-
  local turns = 0
95+
96-
    while true do
96+
97-
    if turtle.detect() then
97+
  if not turtle.detect() then
98-
      turtle.dig()
98+
    print("No Block to place items into")
99
    return
100
  end 
101-
    turtle.turnRight()
101+
  -- Fuel is in slot 1, never empty this
102-
    turns = turns + 1
102+
  for i = 2, 16 do
103-
    if (turns == 4) then
103+
104-
      turns = 0
104+
105-
      print("No chest detected.. waiting")
105+
106-
      sleep(5)
106+
  print("Inventory successfully emptied")
107-
    end    
107+
108
109
local function FirstMining(amount)
110
  for i = 1, amount do
111-
local function PlaceEnderChest()
111+
    if ContinueDigging() then
112-
  turtle.select(chestSlot)
112+
      DigRow()
113-
  while true do
113+
      digDeepAmount = digDeepAmount + 1
114-
    if not turtle.place() then
114+
115-
      print("Cannot place chest for ending, waiting...")
115+
116-
      sleep(5)
116+
117
  end
118
  
119
  turtle.turnLeft()
120
  turtle.turnLeft()
121
  while (digDeepAmount > 1) do
122
    forward()
123-
local function GetChest()
123+
    digDeepAmount = digDeepAmount - 1
124
  end  
125
  turtle.turnLeft()
126-
  turtle.select(chestSlot)
126+
127
end
128
129
local function MiningLoop(amount)
130
  for i = 1, amount do
131
    stripeIndex = i
132-
    PlaceChest()
132+
133
    if continueDigging() then
134-
    GetChest()
134+
      print("Successfully mined stripe #"..i)
135
    else
136-
    turtle.turnRight()
136+
      print("Full inventory, aborted mining stripe #"..i)
137-
    for i = 1, 2 do
137+
138-
        turtle.dig()
138+
139-
        turtle.forward()
139+
140
    if (i < amount) then
141
      turtle.turnRight()
142
      for j = 1, 3 do
143
          forward()
144
      end
145-
PickUpEnderChest()
145+
146
    end
147
  end
148
149-
PlaceEnderChest()
149+
150
  for i = 1, (stripeIndex - 1) * 3 do
151
    forward()
152
  end
153
  turtle.turnRight()
154
end
155
156
FindChest()
157
mineToBase(digDownAmount)
158
MiningLoop(stripeAmount)
159
moveToTop(digDownAmount)
160
EmptyInventory()
161
print ("Run successfully!")