View difference between Paste ID: 2cQZQLVM and YttTamkY
SHOW: | | - or go back to the newest paste.
1
--=======================================Standard Lbrary=====================================--
2
function smartFuel()
3
    if turtle.getFuelLevel() <= 0 then
4
        onSlot = turtle.getSelectedSlot()
5
        while not turtle.refuel(1) do
6
           
7
            onSlot = onSlot + 1
8
            if onSlot == 17 then
9
              onSlot = 1
10
            end
11
            turtle.select(onSlot)
12
        end
13
    end
14
end
15
 
16
function smartFor()
17
    while not turtle.forward() do
18
        turtle.attack()
19
        turtle.dig()
20
        smartFuel()
21
    end
22
end
23
 
24
function smartUp()
25
    while not turtle.up() do
26
        turtle.attackUp()
27
        turtle.digUp()
28
        smartFuel()
29
    end
30
end
31
 
32
function smartDown()
33
    while not turtle.down() do
34
        turtle.attackDown()
35
        turtle.digDown()
36
        smartFuel()
37-
		cleanse()
37+
38
end
39
 
40
function smartMove(dir)
41
    if dir == -1 then
42
        turtle.turnLeft()
43
        smartFor()
44
    elseif dir == 1 then
45
        turtle.turnRight()
46
        smartFor()
47
    elseif dir == 2 then
48
        smartFor()
49
    elseif dir == -2 then
50
        turtle.turnRight()
51
        turtle.turnRight()
52
        smartFor()
53
    elseif dir == 3 then
54
        smartUp()
55
    elseif dir == -3 then
56
        smartDown()
57
    end
58
end
59
--=======================================CoodLibrary==========================-
60-
--=======================================Quarry Functions=====================================--
60+
--start with "initCoords
61-
--======inputVars======--
61+
--====initCoords=====--
62-
function inputVars()
62+
function initCoords()
63-
print("Enter Approx. height")
63+
x = 0
64-
CHUNKS = tonumber(read())/4
64+
y = 0
65-
print("Enter approx. width")
65+
z = 0
66-
PITS = tonumber(read())/5
66+
--0 is forwards, 1 is left, goes clockwise to 3
67-
print("Enter Dive (Amount to go down before starting)")
67+
facing = 0
68-
DIVE = tonumber(read())
68+
69-
print("Enter Depth")
69+
--used to remember location before returning to origin
70-
DEPTH = tonumber(read())
70+
tempX = 0
71-
coalEstimate = math.ceil(((((((6+(DEPTH*2))*CHUNKS)*2)*PITS)+(DIVE*2))/80)*1.1)
71+
tempY = 0
72-
print("This quarry will require approximately " .. tostring(coalEstimate) .. " coal to complete. Is what you entered correct? Enter 'N' to re enter input, or any other button to start quarry")
72+
tempZ = 0
73-
if read() == "N" then
73+
tempFacing = 0
74-
	inputVars()
74+
75
76
function trackedFor()
77
smartFor()
78
if facing == 0 then
79
	y = y+1
80
elseif facing == 1 then
81-
DEPTH = 1
81+
	x = x+1
82-
--how deep do I go before I start the quarry?
82+
elseif facing == 2 then
83-
DIVE = 0
83+
	y = y-1
84
elseif facing == 3 then
85
	x = x-1
86-
--which ores not to mine
86+
87-
blackList = {"minecraft:stone","minecraft:grass","minecraft:dirt","minecraft:sand","minecraft:gravel","minecraft:sandstone","minecraft:cobblestone"}
87+
88-
--copper, uran,yellorite,marble,tin,lead, alu, silver, quartz
88+
89-
--======dump======--
89+
function trackedUp()
90-
function dump()
90+
smartUp()
91-
	for x = 1,16 do
91+
z = z+1
92-
			itemData = turtle.getItemDetail(x)
92+
93-
		if itemData then
93+
94-
			if onBlackList(itemData.name) then
94+
function trackedDown()
95-
				turtle.select(x)
95+
smartDown()
96-
				turtle.drop()
96+
z = z-1
97-
			end
97+
98-
		end
98+
99
function trackedRight()
100
changeFacing(1)
101-
--======hasRoom======--
101+
turtle.turnRight()
102-
--returns if no slot is empty
102+
103-
function hasRoom()
103+
104-
	for x = 1,16 do
104+
function trackedLeft()
105-
		if turtle.getItemCount(x) == 0 then
105+
changeFacing(-1)
106-
			return true
106+
turtle.turnLeft()
107-
		end
107+
108
function trackedMove(dir)
109
	if dir == -1 then
110-
	return false
110+
        trackedLeft()
111
        trackedFor()
112-
--======onBlackList======--
112+
113-
function onBlackList(target)
113+
        trackedRight()
114-
	for z = 0,table.getn(blackList) do
114+
        trackedFor()
115-
		if target == blackList[z] then
115+
116-
			return true
116+
        trackedFor()
117-
		end
117+
118
        trackedRight()
119-
	
119+
        trackedRight()
120-
	return false
120+
        trackedFor()
121
    elseif dir == 3 then
122-
--======smartComp======--
122+
        trackedUp()
123-
function smartComp()
123+
124-
	local sucess, data = turtle.inspect()
124+
        trackedDown()
125-
	if sucess then
125+
126-
		if not onBlackList(data.name) then
126+
127-
			turtle.dig()
127+
128-
		end
128+
function changeFacing(change)
129
	facing = facing + change
130
	facing = facing % 4
131-
--=====dropAll======--
131+
132-
--excludes slot 2, saved for fuel
132+
133-
function dropAll()
133+
function face(targetFacing)
134-
	for c = 3, 16 do
134+
	while facing ~= targetFacing do
135-
		turtle.select(c)
135+
		turtle.turnRight()
136-
		turtle.drop()
136+
		changeFacing(1)
137
		
138
	end
139-
--======Store======--
139+
140-
function store()
140+
141-
	turtle.dig()
141+
function toCoords(tarX,tarY,tarZ,tarFace)
142-
	turtle.select(1)
142+
143-
	turtle.place()
143+
144-
	dropAll()
144+
if z > tarZ then
145-
	turtle.select(1)
145+
	for i=tarZ+1,z do
146-
	turtle.dig()
146+
		trackedMove(-3)
147
	end
148-
--======cleanse======--
148+
elseif z < tarZ  then 
149-
function cleanse()
149+
	for i=z,tarZ-1 do
150-
	data = turtle.getItemDetail(16)
150+
		trackedMove(3)
151-
	if data then
151+
152-
		dump()
152+
153-
		--store()
153+
154
if y > tarY then
155
	face(2)
156-
--======smartMine======--
156+
	for i=tarY+1,y do
157-
function smartMine(dir)
157+
		trackedMove(2)
158-
	smartMove(3*dir)
158+
159-
	smartComp()
159+
elseif y < tarY then 
160-
	turtle.turnRight()
160+
	face(0)
161-
	smartComp()
161+
	for i=y,tarY-1 do
162-
	turtle.turnRight()
162+
		trackedMove(2)
163-
	smartComp()
163+
164-
	turtle.turnRight()
164+
165-
	smartComp()
165+
166-
	turtle.turnRight()
166+
if x > tarX then
167
	face(3)
168-
--======Scale======--
168+
	for i=tarX+1,x do
169-
--must be facing "east"
169+
		trackedMove(2)
170-
function scale(dir)
170+
171
elseif x < tarX then
172-
	for i = 0, DEPTH, 1 do
172+
	face(1) 
173-
		if dir == -1 then
173+
	for i=x,tarX-1 do
174-
			smartMine(-1)
174+
		trackedMove(2)
175-
		elseif dir == 1 then
175+
176-
			smartMine(1)
176+
177-
		end
177+
178
face(tarFace)
179-
	smartMove(1)
179+
180-
	smartMove(-1)
180+
181-
	smartMove(2)
181+
182
function saveCoords()
183
tempX = x
184-
--======chunk(2 holes in the ground)======--
184+
tempY = y
185-
function chunk()
185+
tempZ = z
186-
	scale(-1)
186+
tempFacing = facing
187-
	scale(1)
187+
188
189-
--======Slice(a line of some chunks)======--
189+
function toSavedCoords()
190-
--1 is west, -1 is east
190+
toCoords(tempX,tempY,tempZ,tempFacing)
191-
function slice(dir)
191+
192-
	for j = 0,CHUNKS-1 do
192+
193-
		chunk()
193+
--============================Function Start=============================--
194
initCoords()
195
toCoords(2,2,2,0)
196-
	if dir == 1 then
196+
saveCoords()
197-
		smartMove(-1)
197+
toCoords(0,0,0,0)
198-
		smartMove(2)
198+
toSavedCoords()
199-
		smartMove(2)
199+
print(x .. " " .. y .. " " .. z .. " " ..facing)