View difference between Paste ID: 1FBrE21V and nFSUKiYE
SHOW: | | - or go back to the newest paste.
1
    ------------------------------------------------------------------
2
    --              Turtle Automatic Lava Collection                --
3
    --               By Scott Chamberlain (leftler)                 --
4
    -- Usage: place bucket in inventory and call with the           --
5
    --  arguments <blocks> [drop]                                   --
6
    --                                                              --
7
    -- The turtle travels 'blocks' forward and sucks all lava as    --
8
    -- fuel in then makes a U-turn and attempts to retreive lava on --
9
    -- the way back. The seccond parameter will tell the turtle to  --
10
    -- drop that many blocks after moving forward once.             --
11
    --                                                              --
12
    -- if the turtle is a mining turtle it will break any blocks    --
13
    -- blocking it's path                                           --
14
    ------------------------------------------------------------------
15
     
16
    local tArgs = { ... }
17
     
18
    if #tArgs == 0 then
19
      print("Usage: <blocks> [drop]")
20
      return
21
    end
22
     
23
    turtle.refuel()
24
     
25
    if turtle.getFuelLevel() == 0 then
26
      print("The turtle must have at least some fuel to start with.")
27
      return
28
    elseif turtle.getFuelLevel() == "unlimited" then
29
      print("This turtle does not use fuel to move")
30
      return
31
    end
32
     
33
    --Number of blocks to travel to get the lava
34
    local maxDistance = tArgs[1]
35
     
36
    --How deep to go to gather the lava
37
    local drop = 0
38
    if #tArgs >= 2 then
39
      drop = tonumber(tArgs[2])
40
    end  
41
     
42
    --local counter for how far the turtle has travle
43
    local traveled = 0
44
     
45
    --A helper function to try and move forward, it will attempt to dig if it is blocked.
46
    local function moveForward()
47
      if turtle.forward() == false then
48
        --Failed to move, see if we can dig our way forward
49
        while turtle.dig() do
50
              --Keep digging till we can't dig any more, in case gravel is falling.
51
            end
52
            if turtle.forward() == false then
53
              print("I am either blocked or out of fuel.")
54
              return false
55
            end
56
      end
57
      return true  
58
    end
59
     
60
    --A helper function to try and move down, it will attempt to dig if it is blocked.
61
    local function moveDown()
62
      if turtle.down() == false then
63
        --Failed to move, see if we can dig our way down
64
        turtle.digDown()
65
            if turtle.down() == false then
66
              print("I am either blocked or out of fuel.")
67
              return false
68
            end
69
      end
70
      return true  
71
    end
72
     
73
    --A helper function to try and move down, it will attempt to dig if it is blocked.
74
    local function moveUp()
75
      if turtle.up() == false then
76
        --Failed to move, see if we can dig our way down
77
        while turtle.digUp() do
78
              --Keep digging till we can't dig any more, in case gravel is falling.
79
            end
80
            if turtle.up() == false then
81
              print("I am either blocked or out of fuel.")
82
              return false
83
            end
84
      end
85
      return true  
86
    end
87
     
88
    dropDone = false
89
     
90
    --Attempt to travel to max distance for getting lava
91
    for i = 1, maxDistance do
92
      if moveForward() == false then
93
        print("Could not move forward the full requested distance, starting U-Turn early.")
94
            break
95
      end
96
      traveled = traveled + 1
97
     
98
      --drop to the requested depth
99
      if(dropDone == false) then
100
        for j = 1, drop do
101
              if moveDown() == false then
102
                print("Could not drop the full distance")
103
                    drop = j - 1
104
                    end
105
            end
106
            dropDone = true
107
      end
108
     
109
      --grab the fule
110
      turtle.placeDown()
111
      if turtle.refuel() == false then
112
        --Whatever we picked up is invalid for fuel, put it back down
113
        turtle.placeDown()
114
      end
115
    end
116
     
117
    --Turn around move a block over and get more lava
118
    turtle.turnRight()
119
    moveForward()
120
    turtle.turnRight()
121
     
122
    --Travel back the same number of blocks we came
123
    for i = 1, traveled do
124
      turtle.placeDown()
125
      turtle.refuel()
126
     
127
      --Check to see if we need to go up yet
128
      if i == traveled then
129
        for j = 1, drop do
130
              moveUp()
131
            end
132
      end
133
     
134
      if moveForward() == false then
135
        --We are stuck, attempt to go up a level to get home
136
            if drop > 0 then
137
              repeat
138
                moveUp()
139
                drop = drop - 1
140
                    lastMove = moveForward()
141
              until lastMove == true or drop == 0
142
             
143
              if lastMove == false then
144
                print("I am stuck!")
145
              end
146
            end
147
      end
148
    end
149
     
150
    turtle.turnRight()
151
    moveForward()
152
    turtle.turnRight()