forked from Starkus/quarry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
farmTrees.lua
152 lines (135 loc) · 2.61 KB
/
farmTrees.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
os.loadAPI("inv")
os.loadAPI("t")
local LOG = "minecraft:log"
local SAP = "minecraft:sapling"
local COAL = "minecraft:coal"
local x = 0
local y = 0
function chestyStuff()
-- We can't see what's on the chest
-- so we just grab everything
while turtle.suck() do end
inv.stackItems()
-- and we drop back all the logs
while inv.selectItem(LOG) do
turtle.drop()
end
-- Drop all but one stack of coal
while inv.getItemCount(COAL) > 128 do
inv.selectItem(COAL)
turtle.drop()
end
while inv.getItemCount(SAP) > 128 do
inv.selectItem(SAP)
turtle.drop()
end
end
function refuelIfNeeded()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel < 70 then
print("Fuel level is " .. fuelLevel .. ", refueling...")
if inv.selectItem(COAL) then
turtle.refuel(1)
print("Refueled! new level is " .. turtle.getFuelLevel())
return true
end
printError("No fuel in inventory!")
end
return false
end
function placeSapling()
for i=1, 16 do
turtle.select(i)
local data = turtle.getItemDetail()
if (data and data.name == SAP) then
turtle.place()
break
end
end
end
function chop()
turtle.dig()
t.fw()
local success = true
local data
while success do
success, data = turtle.inspectUp()
if data.name == LOG then
t.digUp()
t.up()
else
break
end
end
while turtle.detectDown() == false do
success = t.down()
end
turtle.back()
placeSapling()
end
function inFrontOfTree()
local success, data
success, data = turtle.inspect()
if data.name == LOG then
return true
end
return false
end
function rowOfTrees()
local foundAny = false
local success, data = turtle.inspect()
if success and (data.name == LOG or data.name == SAP) then
foundAny = true
if data.name == LOG then
inv.selectItem(LOG)
chop()
end
turtle.turnRight()
t.fw(3)
x = x+3
turtle.turnLeft()
rowOfTrees()
end
if x > 0 then
turtle.turnLeft()
while x > 0 do
t.fw()
x = x-1
end
turtle.turnRight()
end
return foundAny
end
function columns(colCount)
for column=1, colCount do
refuelIfNeeded()
turtle.turnRight()
t.fw()
x = x + 1
turtle.turnLeft()
local foundAny = rowOfTrees()
if foundAny == false or column >= colCount then
break
else
t.fw(3)
y = y + 3
end
end
-- Go back
turtle.turnLeft()
turtle.turnLeft()
while y > 0 do
t.fw()
y = y - 1
end
turtle.turnRight()
turtle.turnRight()
end
while true do
refuelIfNeeded()
columns(8)
turtle.turnLeft()
chestyStuff()
turtle.turnRight()
sleep(10)
end