SHOW:
|
|
- or go back to the newest paste.
| 1 | local x,y = 0,0 | |
| 2 | local direction = "north" | |
| 3 | ||
| 4 | local success, idtable = turtle.inspectDown() | |
| 5 | ||
| 6 | if success and idtable.name == "minecraft:chest" then | |
| 7 | print("Success")
| |
| 8 | else | |
| 9 | error("Need chest below turtle to start farming!")
| |
| 10 | end | |
| 11 | ||
| 12 | function testForAvailableFuel() | |
| 13 | for i = 1, 16 do | |
| 14 | turtle.select(i) | |
| 15 | if turtle.refuel(0) then | |
| 16 | return true | |
| 17 | end | |
| 18 | end | |
| 19 | return false | |
| 20 | end | |
| 21 | ||
| 22 | function fuel() | |
| 23 | local fLimit = turtle.getFuelLimit() | |
| 24 | local fCurr = turtle.getFuelLevel() | |
| 25 | local fSucc = testForAvailableFuel() | |
| 26 | if fCurr <= math.floor(fLimit/2) and fSucc == true then | |
| 27 | for i = 1, 16 do | |
| 28 | turtle.select(i) | |
| 29 | if turtle.refuel(0) then | |
| 30 | local halfStack = math.floor(turtle.getItemCount(i)/2) | |
| 31 | turtle.refuel(halfStack) | |
| 32 | end | |
| 33 | end | |
| 34 | end | |
| 35 | end | |
| 36 | ||
| 37 | function forward(dirToGo) | |
| 38 | if dirToGo == "north" then | |
| 39 | y = y + 1 | |
| 40 | if direction == "north" then | |
| 41 | turtle.forward() | |
| 42 | elseif direction == "south" then | |
| 43 | turtle.turnLeft() | |
| 44 | turtle.turnLeft() | |
| 45 | turtle.forward() | |
| 46 | elseif direction == "west" then | |
| 47 | turtle.turnRight() | |
| 48 | turtle.forward() | |
| 49 | elseif direction == "east" then | |
| 50 | turtle.turnLeft() | |
| 51 | turtle.forward() | |
| 52 | end | |
| 53 | direction = "north" | |
| 54 | elseif dirToGo == "east" then | |
| 55 | x = x + 1 | |
| 56 | if direction == "north" then | |
| 57 | turtle.turnRight() | |
| 58 | turtle.forward() | |
| 59 | elseif direction == "west" then | |
| 60 | turtle.turnLeft() | |
| 61 | turtle.turnLeft() | |
| 62 | turtle.forward() | |
| 63 | elseif direction == "east" then | |
| 64 | turtle.forward() | |
| 65 | elseif direction == "south" then | |
| 66 | turtle.turnLeft() | |
| 67 | turtle.forward() | |
| 68 | end | |
| 69 | direction = "east" | |
| 70 | elseif dirToGo == "south" then | |
| 71 | y = y - 1 | |
| 72 | if direction == "south" then | |
| 73 | turtle.forward() | |
| 74 | elseif direction == "north" then | |
| 75 | turtle.turnLeft() | |
| 76 | turtle.turnLeft() | |
| 77 | turtle.forward() | |
| 78 | elseif direction == "east" then | |
| 79 | turtle.turnRight() | |
| 80 | turtle.forward() | |
| 81 | elseif direction == "west" then | |
| 82 | turtle.turnLeft() | |
| 83 | turtle.forward() | |
| 84 | end | |
| 85 | direction = "south" | |
| 86 | elseif dirToGo == "west" then | |
| 87 | x = x - 1 | |
| 88 | if direction == "west" then | |
| 89 | turtle.forward() | |
| 90 | elseif direction == "east" then | |
| 91 | turtle.turnLeft() | |
| 92 | turtle.turnLeft() | |
| 93 | turtle.forward() | |
| 94 | elseif direction == "south" then | |
| 95 | turtle.turnRight() | |
| 96 | turtle.forward() | |
| 97 | elseif direction == "north" then | |
| 98 | turtle.turnLeft() | |
| 99 | turtle.forward() | |
| 100 | end | |
| 101 | direction = "west" | |
| 102 | end | |
| 103 | fuel() | |
| 104 | end | |
| 105 | ||
| 106 | function moveTo(x2, y2) | |
| 107 | if x2 > x then | |
| 108 | local x3 = x2 - x | |
| 109 | for f = 1, x3 do | |
| 110 | forward("east")
| |
| 111 | end | |
| 112 | elseif x2 < x then | |
| 113 | local x3 = (math.abs(x2)) - x | |
| 114 | for f = 1, x3 do | |
| 115 | forward("west")
| |
| 116 | end | |
| 117 | end | |
| 118 | if y2 > y then | |
| 119 | local y3 = y2 - y2 | |
| 120 | for g = 1, y3 do | |
| 121 | forward("north")
| |
| 122 | end | |
| 123 | elseif y2 < y then | |
| 124 | local y3 = (math.abs(y2)) - y2 | |
| 125 | for g = 1, y3 do | |
| 126 | forward("south")
| |
| 127 | end | |
| 128 | end | |
| 129 | end | |
| 130 | ||
| 131 | function dropOff() | |
| 132 | moveTo(0,0) | |
| 133 | for i = 1, 16 do | |
| 134 | turtle.select(i) | |
| 135 | turtle.dropDown() | |
| 136 | end | |
| 137 | turtle.suckDown() | |
| 138 | end | |
| 139 | ||
| 140 | function findSeeds() | |
| 141 | for i = 1, 16 do | |
| 142 | turtle.select(i) | |
| 143 | local idtable = turtle.getItemDetail() | |
| 144 | if idtable.name == "minecraft:wheat_seeds" then | |
| 145 | return i | |
| 146 | end | |
| 147 | end | |
| 148 | end | |
| 149 | ||
| 150 | function harvestGrownAndPlant() | |
| 151 | local success, idtable = turtle.inspectDown() | |
| 152 | if success then | |
| 153 | if idtable.state.age == 7 then | |
| 154 | local seeds = findSeeds() | |
| 155 | turtle.digDown() | |
| 156 | turtle.select(seeds) | |
| 157 | turtle.placeDown() | |
| 158 | end | |
| 159 | end | |
| 160 | end | |
| 161 | ||
| 162 | function harvestAll() | |
| 163 | moveTo(0, 1) | |
| 164 | for k = 1, 27 do | |
| 165 | for p = 1, 27 do | |
| 166 | moveTo(p, k) | |
| 167 | harvestGrownAndPlant() | |
| 168 | end | |
| 169 | end | |
| 170 | moveTo(0,0) | |
| 171 | end | |
| 172 | ||
| 173 | while true do | |
| 174 | dropOff() | |
| 175 | harvestAll() | |
| 176 | sleep(600) | |
| 177 | end |