View difference between Paste ID: BwDNqWSr and wuNdXM6w
SHOW: | | - or go back to the newest paste.
1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2
-- Name: DanielKermanStripMining (DKSM)   --
3
-- Author: Daniel_Kerman                  --
4
-- Version: 1.0.1                         --
5
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
6
7
8
-- Initializing --
9
10
local rowsMined = {0}
11
local totalRows = {0}
12
local hallLength = {0}
13
local fuelNeeded = {0}
14
local fuelLevel = turtle.getFuelLevel() 
15
local fuelLimit = turtle.getFuelLimit()
16
local startConfirmed = "No"
17
local slot = turtle.getSelectedSlot()
18
local itemSpace = turtle.getItemSpace()
19-
local torchCounter = 0
19+
local it = 0
20
21
-- Declaring Functions --
22
23-
function forward() -- Help from the user Foogles (http://www.computercraft.info/forums2/index.php?/user/46239-foogles/) -- THANK YOU FOR THIS BUG SOLUTION!
23+
24-
  local x = turtle.forward()
24+
25-
  if (x == false) then
25+
26-
        return forward()
26+
27-
  end
27+
28
	elseif row == nil then
29
		row = 1
30
	elseif column == nil then
31
		column = 1
32
	end
33
	term.setCursorPos(column,row)
34
end
35
36
local function checkNumber(varToCheck)
37
	assert(type(varToCheck) == "number", "Program expected number. Got string or something else instead.")
38
end
39
40
local function fallingBlock()
41
local success, data = turtle.inspect()
42
local fBlocks = 
43
{
44
sand="minecraft:sand",
45
gravel="minecraft:gravel",
46
anvil="minecraft:anvil",
47
dragon_egg="minecraft:dragon_egg"
48
}
49
	if data.name==fBlocks.sand or data.name==fBlocks.gravel or data.name==fBlocks.anvil or data.name==fBlocks.dragon_egg then
50
		return true
51
	else
52
		return false
53
	end
54
end
55
56
local function dig(length,back)
57
for i=1, length do
58
	it=it+1	
59
	while fallingBlock() == true do
60
		turtle.dig()
61
		sleep(1)
62
	end
63
	turtle.dig()
64
	turtle.forward()
65-
	torchCounter=torchCounter+1	
65+
66
	if it >= 8 then
67
		turtle.select(16)
68
		print("Place Torch")
69
		local data = turtle.getItemDetail()
70
		if data.name == "minecraft:torch" then
71-
	forward()
71+
72
		end
73-
	if torchCounter >= 8 then
73+
		it = 0
74
		turtle.select(1)
75-
		if turtle.getItemSpace() < 64 then
75+
76
end
77
if back == true then
78
turtle.turnLeft()
79
turtle.turnLeft()
80-
		end	
80+
81-
		torchCounter = 0
81+
	turtle.forward()
82
end
83
turtle.forward()
84
turtle.turnLeft()
85
turtle.turnLeft()
86
end
87
88
end
89-
	forward()
89+
90
-- Welcome + User input --
91-
forward()
91+
92
clear(1,1)
93
94
print("Welcome to the Strip Mining Program.")
95
sleep(1)
96
print("Please enter a Hall/Strip Length (x = x block/s): ")
97
hallLength[1] = io.read()
98
hallLength[1] = tonumber(hallLength[1])
99
checkNumber(hallLength[1])
100
print("Please enter a number of rows:")
101
totalRows[1] = io.read()
102
totalRows[1] = tonumber(totalRows[1])
103
checkNumber(totalRows[1])
104
print("Calculating if turtle has enough fuel...")
105
fuelNeeded[1] = (hallLength[1]*3*totalRows[1])+(12*totalRows[1])
106
sleep(1.0)
107
assert(fuelNeeded[1]<fuelLimit, "Your fuel Limit is too low. Try an advanced turtle.")
108
assert(fuelNeeded[1]<fuelLevel, "Your turtle hasn't enought fuel.")
109
print("Your turtle has enough fuel. Please place a chest behind the turtle.")
110
sleep(2.0)
111
clear(1,1)
112
print("Place a chest behind the turtle.")
113
print("Place Torches to place in Slot 16 (Bottom right hand corner)")
114
write("Press any key to start the program.")
115
local skip = io.read()
116
117
-- Post initialization -- 
118
119
local rowsToMine = totalRows[1]-rowsMined[1]
120
clear(1,1)
121
turtle.select(1)
122
123
-- Main Loop --
124
125
for i=1, totalRows[1] do
126
	turtle.select(1)
127
	dig(3,false) 
128
	turtle.turnLeft()
129
	dig(hallLength[1],true)
130
	rowsMined[1] = rowsMined[1]+1
131
	clear(1,1)
132
	print("Rows Mined: ",rowsMined[1])
133
	local z = 1
134
	turtle.select(15)
135
	if turtle.getItemSpace() < 64 then
136
		turtle.turnLeft()
137
		for i=1,rowsMined[1]*3+1 do
138
			turtle.forward()
139
		end
140
		for i=1,15 do
141
			turtle.select(z)
142
			z=z+1
143
			turtle.drop(64)
144
		end
145
		turtle.turnRight()
146-
			forward()
146+
147
		for i=1,rowsMined[1]*3+1 do
148
			turtle.forward()
149
		end
150
		turtle.turnLeft()
151
	end
152
	turtle.turnRight()
153
	rowsToMine = totalRows[1]-rowsMined[1]
154
end
155
156-
			forward()
156+
157
158
do
159
	print("Putting Items into chest.")
160
	turtle.turnLeft()
161
	turtle.turnLeft()
162
	for i=1, (rowsMined[1]*3)+1 do
163
		turtle.forward()
164
	end
165
	z=1
166
    for i=1,16 do
167
			turtle.select(z)
168
			z=z+1
169
			turtle.drop(64)
170
	end
171-
		forward()
171+
172
173
turtle.select(1)
174
175
print("Mining Complete.")
176
177
sleep(2)
178
179
clear(1,1)