SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Based on excavate from the original computercraft distribution | |
| 2 | -- written by hildenae | |
| 3 | rubberwood=1 | |
| 4 | tool=2 | |
| 5 | ||
| 6 | local depth = 0 | |
| 7 | local xPos,zPos = 0,0 | |
| 8 | local xDir,zDir = 0,1 | |
| 9 | ||
| 10 | local function turnLeft() | |
| 11 | turtle.turnLeft() | |
| 12 | xDir, zDir = -zDir, xDir | |
| 13 | end | |
| 14 | ||
| 15 | local function turnRight() | |
| 16 | turtle.turnRight() | |
| 17 | xDir, zDir = zDir, -xDir | |
| 18 | end | |
| 19 | ||
| 20 | function goTo( x, y, z, xd, zd ) | |
| 21 | while depth > y do | |
| 22 | if turtle.up() then | |
| 23 | depth = depth - 1 | |
| 24 | else | |
| 25 | return false | |
| 26 | end | |
| 27 | end | |
| 28 | ||
| 29 | if xPos > x then | |
| 30 | while xDir ~= -1 do | |
| 31 | turnLeft() | |
| 32 | end | |
| 33 | while xPos > x do | |
| 34 | if turtle.forward() then | |
| 35 | xPos = xPos - 1 | |
| 36 | else | |
| 37 | return false | |
| 38 | end | |
| 39 | end | |
| 40 | elseif xPos < x then | |
| 41 | while xDir ~= 1 do | |
| 42 | turnLeft() | |
| 43 | end | |
| 44 | while xPos < x do | |
| 45 | if turtle.forward() then | |
| 46 | xPos = xPos + 1 | |
| 47 | else | |
| 48 | return false | |
| 49 | end | |
| 50 | end | |
| 51 | end | |
| 52 | ||
| 53 | if zPos > z then | |
| 54 | while zDir ~= -1 do | |
| 55 | turnLeft() | |
| 56 | end | |
| 57 | while zPos > z do | |
| 58 | if turtle.forward() then | |
| 59 | zPos = zPos - 1 | |
| 60 | else | |
| 61 | return false | |
| 62 | end | |
| 63 | end | |
| 64 | elseif zPos < z then | |
| 65 | while zDir ~= 1 do | |
| 66 | turnLeft() | |
| 67 | end | |
| 68 | while zPos < z do | |
| 69 | if turtle.forward() then | |
| 70 | zPos = zPos + 1 | |
| 71 | else | |
| 72 | return false | |
| 73 | end | |
| 74 | end | |
| 75 | end | |
| 76 | while depth < y do | |
| 77 | if turtle.down() then | |
| 78 | depth = depth + 1 | |
| 79 | else | |
| 80 | return false | |
| 81 | end | |
| 82 | end | |
| 83 | while zDir ~= zd or xDir ~= xd do | |
| 84 | turnLeft() | |
| 85 | end | |
| 86 | return true | |
| 87 | end | |
| 88 | ||
| 89 | local function forward() | |
| 90 | turtle.forward() | |
| 91 | xPos = xPos + xDir | |
| 92 | zPos = zPos + zDir | |
| 93 | return true | |
| 94 | end | |
| 95 | ||
| 96 | local function down() | |
| 97 | if turtle.down() then | |
| 98 | depth = depth + 1 | |
| 99 | return true | |
| 100 | else | |
| 101 | return false | |
| 102 | end | |
| 103 | end | |
| 104 | ||
| 105 | local function harvest() | |
| 106 | if turtle.compareTo(rubberwood) then | |
| 107 | turtle.select(tool) | |
| 108 | turtle.place() | |
| 109 | end | |
| 110 | end | |
| 111 | ||
| 112 | local function downTree() | |
| 113 | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir | |
| 114 | while(down()) do | |
| 115 | harvest() | |
| 116 | end | |
| 117 | goTo( x,y,z,xd,zd ) | |
| 118 | end | |
| 119 | ||
| 120 | local function moveRight() | |
| 121 | turnRight() | |
| 122 | forward() | |
| 123 | - | downtree() |
| 123 | + | turnLeft() |
| 124 | end | |
| 125 | local function moveLeft() | |
| 126 | - | sleep(60) |
| 126 | + | turnLeft() |
| 127 | forward() | |
| 128 | turnRight() | |
| 129 | end | |
| 130 | run = true | |
| 131 | while run do | |
| 132 | forward() | |
| 133 | downTree() | |
| 134 | moveRight() | |
| 135 | downTree() | |
| 136 | moveRight() | |
| 137 | downTree() | |
| 138 | -- go to charge station | |
| 139 | goTo(0,0,0,0,1) | |
| 140 | run = false | |
| 141 | end |