View difference between Paste ID: 7Ndj1pau and y7LRANmC
SHOW: | | - or go back to the newest paste.
1
--[[
2
This program is designed to setup a 9x9 farm on a level surface with a 
3
water source block in the middle. These dimensions account for the 
4
maximum range a tilled dirt can be from water. If you would prefer to
5
have the farm level with your terrain rather than raised one above it
6
you need only clear a 9x9 hole in the ground and ensure your turtle is
7
placed at the block height you want the farm built at. This program 
8
can handle wheat, carrots, and potatoes. A farming turtle will require 
9
the following items in it's inventory slots:
10
11
1) 64 dirt
12
2) 16 dirt
13
4) bucket of water
14
5) 64 seeds, carrots, or potatoes
15
6) 16 seeds, carrots, or potatoes
16
16) Fuel (preferably coal, charcoal, or a lava bucket)
17
18
Future versions will support pumpkins and melons along with
19
harvesting/replanting code.
20
]]--
21
22
local step = 1 --used to track progression
23
local count = 64 --used to track inventory slots
24
local n = 1 --used to track slot selection
25
26
function fuel()
27
  if turtle.getFuelLevel() < 10 then
28
    select(16)
29
    turtle.refuel(1)
30
  end
31
end
32
33
--assorted functions to shorten/tidy my actual code
34
function left(reps)
35
  for x=1,reps do
36
   turtle.turnLeft()
37
  end
38
end
39
40
function right(reps)
41
  for x=1,reps do
42
   turtle.turnRight()
43
  end
44
end
45
46
function back(reps)
47
  for x=1,reps do
48
   fuel() 
49
   turtle.back()
50
  end
51
end
52
53
function forward(reps)
54
  for x=1,reps do
55
   fuel()
56
   turtle.forward()
57
  end
58
end
59
60
function up(reps)
61
  for x=1,reps do
62
   fuel()
63
   turtle.up()
64
  end
65
end
66
67
function down(reps)
68
  for x=1,reps do
69
   fuel()
70
   turtle.down()
71
  end
72
end
73
74
function pDown()
75
  turtle.placeDown()
76
end
77
78
function pUp()
79
  turtle.placeUp()
80
end
81
82
function place()
83
  turtle.place()
84
end
85
86
function dDown()
87
  turtle.digDown()
88
end
89
90
function select(slot)
91
  turtle.select(slot)
92
end
93
94
--Turtle positions itself and begins creating the farm
95
up(1)
96
right(2)
97
back(1)
98
select(1)
99
pDown()
100
count = count - 1
101
102
--Turtle creates the farm when z == 1 and then tills and plants when z == 2
103
for z=1,2 do
104
  for x=1,9 do
105
    for y=1,8 do
106
      if z == 1 then
107
        if count > 0 then
108
          n=1
109
        else
110
          n=2
111
        end
112
      else
113
        if count > 0 then
114
          n=5
115
        else
116
          n=6
117
        end
118
      end
119
      if turtle.getItemCount(1) == 24 and count == 24 then --tracks for water placement
120
        back(2)
121
        down(1)
122
        select(4)
123
        place()
124
        up(1)
125
        forward(1)
126
      else
127
        back(1)
128
        select(n)
129
        pDown()
130
      end    
131
      count = count - 1
132
    end
133
    if step == 1 then
134
      select(n)
135
      pDown()
136
      right(1)
137
      back(1)
138
      right(1)
139
      if not pDown() then
140
        select(n+1)
141
        pDown()
142
      end
143
      step = 2
144
      count = count - 2
145
    else
146
      select(n)
147
      pDown()
148
      left(1)
149
      back(1)
150
      left(1)
151
      if not pDown() then
152
        select(n+1)
153
        pDown()
154
      end
155
      step = 1
156
      count = count - 2
157
    end
158
  end
159
  for a=1,2 do
160
    right(1)
161
    forward(1)
162
  end
163
  up(1)
164
  count = 64
165
end