-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreecc2.lua
More file actions
149 lines (140 loc) · 3.66 KB
/
treecc2.lua
File metadata and controls
149 lines (140 loc) · 3.66 KB
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
walk = 13
trees = 6 --one side of the trees
CHECKTIME = 120 --seconds
sapChest = "minecraft:chest_4086"
buffer = "minecraft:chest_4091" -- This is the only field that should be edited.
fuelChest = "minecraft:chest_4089"
outputChest = "minecraft:chest_4090"
function fuelOk()
return turtle.getFuelLevel() > walk+trees*2*6*2
end
function justRefuel()
if not fuelOk() then
local fuelchest = peripheral.wrap(fuelChest)
for i, v in pairs(fuelchest.list()) do
if v.name == "minecraft:coal" then
fuelchest.pushItems(buffer, i)
break
end
end
turtle.select(2) --fuel slot
turtle.suck()
turtle.refuel()
if not fuelOk() then --still not enough fuel
print("NEF")
sleep(1000)
end
end
turtle.select(1) -- sapling slot
if turtle.getItemCount() < 20 then
local chest = peripheral.wrap(sapChest)
for i, v in pairs(chest.list()) do
if v.name == "minecraft:sapling" then
chest.pushItems(buffer, i)
turtle.suck(20-turtle.getItemCount())
peripheral.wrap(buffer).pushItems(sapChest, 1)
break
end
end
end
end
function dumpItems()
local buf = peripheral.wrap(buffer)
for i=2,16 do
turtle.select(i)
turtle.drop()
buf.pushItems(outputChest, 1)
end
turtle.select(1)
end
function chopTree()
local worked, thing = turtle.inspect()
if worked and thing.name == "minecraft:log" then
turtle.dig()
turtle.forward()
local success, block = turtle.inspectUp()
while success and block.name=="minecraft:log" do
turtle.digUp()
turtle.up()
success, block = turtle.inspectUp()
end
worked, thing = turtle.inspectDown()
while worked and thing.name == "minecraft:leaves" do
turtle.digDown()
turtle.down()
worked, thing = turtle.inspectDown()
end
while turtle.down() do end
turtle.back()
turtle.place()
end
end
function treeWalk()
for i=1,walk do
turtle.forward()
if i%2 == 1 then
turtle.turnRight()
chopTree()
turtle.turnLeft()
turtle.turnLeft()
chopTree()
turtle.turnRight()
end
end
for i=1, walk do
turtle.back()
end
turtle.turnRight()
end
function reState()
local worked, wood = turtle.inspectDown()
local worked_sap, sap = turtle.inspect()
if worked and wood.name == "minecraft:chest" then
return
elseif worked_sap and (sap.name == "minecraft:sapling" or sap.name == "minecraft:log") then
-- Handle the special case where turtle is staring at sapling or log
turtle.turnRight() -- take a guess
while turtle.forward() do end
local worked_c, chest = turtle.inspect()
if worked_c and chest.name == "minecraft:chest" then
turtle.turnLeft()
return
end
elseif worked and wood.name == "minecraft:chest" then
-- Turtle is sitting on the chest but facing forward
turtle.turnRight()
return
elseif not worked or wood.name == "minecraft:leaves" then
while worked and wood.name == "minecraft:leaves" do
turtle.digDown()
turtle.down()
worked, wood = turtle.inspectDown()
end --will have to break down leaves in future if grow as soon as start
while turtle.down() do end
turtle.forward()
turtle.turnLeft()
local success, block = turtle.inspectDown()
local call = "turnLeft"
if success and block.name == "minecraft:torch" then
call = "turnRight"
end
turtle.turnRight()
turtle.back()
turtle.back()
turtle.place()
turtle[call]()
end
while turtle.back() do end
turtle.turnRight()
end
function begin()
reState()
while true do
justRefuel()
turtle.turnLeft()
treeWalk()
dumpItems()
sleep(CHECKTIME)
end
end
begin()