SHOW:
|
|
- or go back to the newest paste.
| 1 | --IPJ Industries Inc. - Pragmatic Programming by IPJ | |
| 2 | direction="left" | |
| 3 | home=true | |
| 4 | ||
| 5 | function sweep() | |
| 6 | for i = 1, 7 do | |
| 7 | turtle.dig() | |
| 8 | turtle.up() | |
| 9 | end | |
| 10 | - | for i = 1, 8 do |
| 10 | + | turtle.dig() |
| 11 | ||
| 12 | for i = 1, 8 do | |
| 13 | turtle.down() | |
| 14 | end | |
| 15 | end | |
| 16 | ||
| 17 | function rotate() | |
| 18 | turtle.turnRight() | |
| 19 | turtle.forward() | |
| 20 | turtle.turnLeft() | |
| 21 | turtle.forward() | |
| 22 | turtle.turnLeft() | |
| 23 | end | |
| 24 | ||
| 25 | function harvest() | |
| 26 | for i = 1, 4 do | |
| 27 | sweep() | |
| 28 | rotate() | |
| 29 | end | |
| 30 | end | |
| 31 | ||
| 32 | function dumpItems() | |
| 33 | for i = 1, 16 do | |
| 34 | turtle.select(i) | |
| 35 | turtle.drop() | |
| 36 | end | |
| 37 | end | |
| 38 | ||
| 39 | function toggleDirection() | |
| 40 | if direction=="left" then | |
| 41 | print("Direction set to right")
| |
| 42 | direction="right" | |
| 43 | else | |
| 44 | print("Direction set to left")
| |
| 45 | direction="left" | |
| 46 | end | |
| 47 | end | |
| 48 | ||
| 49 | function turn() | |
| 50 | if direction=="left" then | |
| 51 | print("turn left")
| |
| 52 | turtle.turnLeft() | |
| 53 | else | |
| 54 | print("turn right")
| |
| 55 | turtle.turnRight() | |
| 56 | end | |
| 57 | end | |
| 58 | ||
| 59 | function turnBack() | |
| 60 | if direction == "left" then | |
| 61 | print("turnBack right")
| |
| 62 | turtle.turnRight() | |
| 63 | else | |
| 64 | print("turnBack left")
| |
| 65 | turtle.turnLeft() | |
| 66 | end | |
| 67 | end | |
| 68 | ||
| 69 | function goHome() | |
| 70 | turn() | |
| 71 | turn() | |
| 72 | while turtle.forward() do | |
| 73 | end | |
| 74 | if direction=="left" then | |
| 75 | turtle.turnLeft() | |
| 76 | while turtle.forward() do | |
| 77 | end | |
| 78 | turtle.turnRight() | |
| 79 | end | |
| 80 | turtle.turnRight() | |
| 81 | turtle.forward() | |
| 82 | turtle.turnLeft() | |
| 83 | turtle.forward() | |
| 84 | turtle.turnLeft() | |
| 85 | - | print("Sleeping for 5min to recharge")
|
| 85 | + | |
| 86 | - | sleep(300) |
| 86 | + | |
| 87 | print("Sleeping for 15min to recharge")
| |
| 88 | sleep(900) | |
| 89 | end | |
| 90 | ||
| 91 | function goEdge() | |
| 92 | print("Going to edge of wall")
| |
| 93 | while turtle.forward() do | |
| 94 | end | |
| 95 | end | |
| 96 | ||
| 97 | function goDown() | |
| 98 | print("Going down")
| |
| 99 | while turtle.down() do | |
| 100 | end | |
| 101 | end | |
| 102 | ||
| 103 | function resume() | |
| 104 | goDown() | |
| 105 | if turtle.detect() then | |
| 106 | turtle.turnRight() | |
| 107 | end | |
| 108 | goEdge() | |
| 109 | turtle.turnRight() | |
| 110 | goEdge() | |
| 111 | while not checkStartCorner() do | |
| 112 | goNextCorner() | |
| 113 | end | |
| 114 | turtle.turnRight() | |
| 115 | turtle.forward() | |
| 116 | turtle.turnLeft() | |
| 117 | turtle.forward() | |
| 118 | turtle.turnLeft() | |
| 119 | - | print("Sleeping for 5min to recharge")
|
| 119 | + | |
| 120 | - | sleep(300) |
| 120 | + | |
| 121 | print("Sleeping for 15min to recharge")
| |
| 122 | sleep(900) | |
| 123 | end | |
| 124 | ||
| 125 | function checkStartCorner() | |
| 126 | print("Checking for start corner")
| |
| 127 | turtle.up() | |
| 128 | if turtle.detect() then | |
| 129 | turtle.down() | |
| 130 | return true | |
| 131 | end | |
| 132 | turtle.down() | |
| 133 | return false | |
| 134 | end | |
| 135 | ||
| 136 | function goNextCorner() | |
| 137 | print("Going to next corner")
| |
| 138 | turtle.turnRight() | |
| 139 | goEdge() | |
| 140 | end | |
| 141 | ||
| 142 | function nextTree() | |
| 143 | print("Finding next tree")
| |
| 144 | if home then | |
| 145 | print("Home now")
| |
| 146 | turtle.forward() | |
| 147 | home=false | |
| 148 | return true | |
| 149 | else | |
| 150 | turn() | |
| 151 | turtle.forward() | |
| 152 | if not turtle.forward() then | |
| 153 | print("Reached end of row, finding new row")
| |
| 154 | turnBack() | |
| 155 | turtle.forward() | |
| 156 | turtle.forward() | |
| 157 | if turtle.detect()then | |
| 158 | print("Reached last row, going home")
| |
| 159 | goHome() | |
| 160 | direction="left" | |
| 161 | home=true | |
| 162 | return false | |
| 163 | end | |
| 164 | turtle.down() | |
| 165 | turnBack() | |
| 166 | turtle.forward() | |
| 167 | turn() | |
| 168 | toggleDirection() | |
| 169 | else | |
| 170 | turnBack() | |
| 171 | end | |
| 172 | return true | |
| 173 | end | |
| 174 | end | |
| 175 | ||
| 176 | if not turtle.detectUp() then | |
| 177 | resume() | |
| 178 | end | |
| 179 | while true do | |
| 180 | print("Starting Tapping Route...")
| |
| 181 | while nextTree() do | |
| 182 | harvest() | |
| 183 | end | |
| 184 | end |