-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarming.lua
74 lines (64 loc) · 1.4 KB
/
farming.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
os.loadAPI("common")
USE_CROP = false
if common.toBoolean(arg[1]) then USE_CROP = true end
sX = 0
if arg[2] then sX = tonumber(arg[2]) end
sY = 0
if arg[3] then sY = tonumber(arg[3]) end
sZ = 0
if arg[4] then sZ = tonumber(arg[4]) end
WIDTH = 4 --tonumber(arg[1])
LENGTH = 10 -- tonumber(arg[2])
CROP_SLOT = 1
SEED_SLOT = 2
function farm()
for i=0,WIDTH-1,1 do
for j=0,LENGTH-2,1 do
common.forward()
pickAndPlant()
end
if i % 2 == 0 then
common.turnRight()
common.forward()
common.turnRight()
else
common.turnLeft()
common.forward()
common.turnLeft()
end
end
end
function pickAndPlant()
success, data = turtle.inspectDown()
if success and data.state.age == 7 then
turtle.select(CROP_SLOT)
turtle.digDown()
SLOT = SEED_SLOT
if USE_CROP then SLOT = CROP_SLOT end
turtle.select(SEED_SLOT)
turtle.placeDown()
end
end
function cleanUp()
common.navigate(3,0,0)
for i=3,15,1 do
turtle.select(i)
turtle.dropDown()
end
end
function dropCrops()
common.navigate(0,0,0)
turtle.select(CROP_SLOT)
ejectCount = turtle.getItemCount() - 1
turtle.dropDown(ejectCount)
end
print("Farming " .. WIDTH .. " x " .. LENGTH .. " plot")
common.gpsInit()
common.navigate(sX,sY,sZ)
common.setDirection("north")
common.reFuel(sX+1,sY,sZ)
farm()
cleanUp()
dropCrops()
common.navigate(0,0,0)
common.setDirection("north")