SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --[[ |
| 1 | + | --[[ |
| 2 | - | 2014 (c) psychedelixx |
| 2 | + | 2015 (c) psychedelixx |
| 3 | - | Minecraft Turtle: Room (Tobust) |
| 3 | + | Minecraft Turtle: Spiral miner (Robust) |
| 4 | - | 2014-04-21 |
| 4 | + | 2015-01-04 |
| 5 | ||
| 6 | - | Digs a room with specified dimensions. |
| 6 | + | Mines in a spiralform (spin me right round baby) and stays on the level it started. |
| 7 | ||
| 8 | Robust API: | |
| 9 | http://computercraft.info/wiki/Robust_Turtle_API | |
| 10 | ||
| 11 | Usage: | |
| 12 | - use turtle and type "label set <name>" | |
| 13 | (to give your turtle an unique name so it remembers its programs) | |
| 14 | - | - type "pastebin get VRR7iLat room" |
| 14 | + | - type "pastebin get 7Ckr8y7s spiral" |
| 15 | - | - type "room <width> [<length>] [<height>]" |
| 15 | + | - type "spiral <limit> [<fillGround 0|1 default 0> <factor default 1.5> <useTesseract 0|1 default 0>]" |
| 16 | - | - default length = width |
| 16 | + | - place chests in slot 16 |
| 17 | - | - default height = 2 |
| 17 | + | ]] |
| 18 | - | - place solid blocks in slot 16 to fill the ground |
| 18 | + | torchesAvailable = false |
| 19 | - | --]] |
| 19 | + | chestsAvailable = false |
| 20 | torchSlot = 15 | |
| 21 | factor = 1.5 | |
| 22 | useTesseract = false | |
| 23 | ||
| 24 | function move() | |
| 25 | slot = 1 | |
| 26 | - | empty = 0 |
| 26 | + | while not turtle.detectDown() and fillGround == 1 do |
| 27 | - | if nextTurnRight then |
| 27 | + | |
| 28 | - | print("w"..w.." l"..l.." h"..h.." next turn right. Fuel: " .. turtle.getFuelLevel())
|
| 28 | + | turtle.placeDown() |
| 29 | - | else |
| 29 | + | |
| 30 | - | print("w"..w.." l"..l.." h"..h.." next turn left. Fuel: " .. turtle.getFuelLevel())
|
| 30 | + | if slot < 13 then |
| 31 | slot = slot+1 | |
| 32 | else | |
| 33 | - | for slot = 1, 16 do |
| 33 | + | print("no items to fill ground")
|
| 34 | fillGround = 0 | |
| 35 | break | |
| 36 | end | |
| 37 | end | |
| 38 | ||
| 39 | t.dig() | |
| 40 | - | t.down(h-1) |
| 40 | + | |
| 41 | t.digUp() | |
| 42 | - | if (h-1)%4==0 then |
| 42 | + | |
| 43 | - | if nextTurnRight then |
| 43 | + | empty = 0 |
| 44 | - | t.left() |
| 44 | + | for slot = 1, 13 do |
| 45 | - | t.forward(w-1) |
| 45 | + | |
| 46 | - | t.left() |
| 46 | + | |
| 47 | - | t.forward(l) |
| 47 | + | |
| 48 | - | else |
| 48 | + | |
| 49 | - | t.right() |
| 49 | + | |
| 50 | - | t.forward(w-1) |
| 50 | + | |
| 51 | - | t.left() |
| 51 | + | --[[ if turtle is full, turn around, place chest, move items into it, turn around and continue ]]-- |
| 52 | - | t.forward(length-l-1) |
| 52 | + | |
| 53 | t.turnAround() | |
| 54 | ||
| 55 | - | if nextTurnRight then |
| 55 | + | if not chestsAvailable then |
| 56 | - | t.right() |
| 56 | + | print("Please put chests in slot 15 and press enter to continue")
|
| 57 | - | t.forward(width-w) |
| 57 | + | read() |
| 58 | - | t.left() |
| 58 | + | end |
| 59 | - | t.forward(length-l-1) |
| 59 | + | |
| 60 | - | else |
| 60 | + | turtle.select(14) |
| 61 | - | t.left() |
| 61 | + | turtle.place() |
| 62 | - | t.forward(width-w) |
| 62 | + | |
| 63 | - | t.left() |
| 63 | + | for slot = 1, 13 do |
| 64 | - | t.forward(l) |
| 64 | + | |
| 65 | turtle.drop() | |
| 66 | end | |
| 67 | ||
| 68 | - | for slot = 1, 15 do |
| 68 | + | if useTesseract then |
| 69 | os.sleep(0.5) | |
| 70 | turtle.select(14) | |
| 71 | turtle.dig() | |
| 72 | end | |
| 73 | ||
| 74 | if turtle.getItemCount(14) > 0 then | |
| 75 | - | if (h-1)%4==0 then |
| 75 | + | chestsAvailable = true |
| 76 | - | if nextTurnRight then |
| 76 | + | else |
| 77 | - | t.forward(l) |
| 77 | + | chestsAvailable = false |
| 78 | - | t.right() |
| 78 | + | end |
| 79 | - | t.forward(w-1) |
| 79 | + | |
| 80 | - | t.left() |
| 80 | + | |
| 81 | - | else |
| 81 | + | |
| 82 | - | t.forward(length-l-1) |
| 82 | + | |
| 83 | - | t.right() |
| 83 | + | |
| 84 | - | t.forward(w-1) |
| 84 | + | |
| 85 | - | t.right() |
| 85 | + | |
| 86 | print("")
| |
| 87 | print("spiral <limit> [<fillGround 0|1 default 0> <factor default 1.5> <useTesseract 0|1 default 0]")
| |
| 88 | - | if nextTurnRight then |
| 88 | + | print("place chests/tesseract in slot 14")
|
| 89 | - | t.forward(length-l-1) |
| 89 | + | print("place torches in slots 15 and 16")
|
| 90 | - | t.right() |
| 90 | + | |
| 91 | - | t.forward(width-w) |
| 91 | + | |
| 92 | - | t.right() |
| 92 | + | |
| 93 | - | else |
| 93 | + | |
| 94 | - | t.forward(l) |
| 94 | + | |
| 95 | - | t.right() |
| 95 | + | limit = tonumber(args[1]) |
| 96 | - | t.forward(width-w) |
| 96 | + | fillGround = 0 |
| 97 | - | t.left() |
| 97 | + | |
| 98 | if #args >= 2 then | |
| 99 | fillGround = tonumber(args[2]) | |
| 100 | end | |
| 101 | - | t.up(h-1) |
| 101 | + | if #args >= 3 then |
| 102 | factor= tonumber(args[3]) | |
| 103 | end | |
| 104 | if #args >= 4 then | |
| 105 | if tonumber(args[4]) > 0 then | |
| 106 | useTesseract = true | |
| 107 | else | |
| 108 | - | print("Usage: room <width> [<length>] [<height>]")
|
| 108 | + | useTesseract = false |
| 109 | - | print("# default length = width")
|
| 109 | + | end |
| 110 | - | print("# default height = 2")
|
| 110 | + | |
| 111 | ||
| 112 | if turtle.getFuelLevel() < 0.75*limit*limit + limit then | |
| 113 | print("I need " .. (0.75*limit*limit + limit) - turtle.getFuelLevel() .. " more fuel!")
| |
| 114 | else | |
| 115 | print("======== 2015 (c) psychedelixx ========")
| |
| 116 | print("Let's go!")
| |
| 117 | - | width = tonumber(args[1]) |
| 117 | + | print("Mining a spiral...")
|
| 118 | - | length = width |
| 118 | + | |
| 119 | - | height = 2 |
| 119 | + | if turtle.getItemCount(15)+turtle.getItemCount(16) > 0 then |
| 120 | torchesAvailable = true | |
| 121 | else | |
| 122 | - | length = tonumber(args[2]) |
| 122 | + | print("")
|
| 123 | print("Warning: no torches found in slot 15 and 16. Press enter to continue")
| |
| 124 | - | if #args == 3 then |
| 124 | + | read() |
| 125 | - | height = tonumber(args[3]) |
| 125 | + | torchesAvailable = false |
| 126 | end | |
| 127 | ||
| 128 | - | if turtle.getFuelLevel() < height*width*length then |
| 128 | + | if turtle.getItemCount(14) > 0 then |
| 129 | - | print("I need " .. height*width*length - turtle.getFuelLevel() .. " more fuel!")
|
| 129 | + | chestsAvailable = true |
| 130 | else | |
| 131 | - | print("======== 2014 (c) psychedelixx ========")
|
| 131 | + | print("")
|
| 132 | print("Warning: no chests found in slot 14. Press enter to continue")
| |
| 133 | - | print("Digging " .. width .. "*" .. length .. "*" .. height .. " (w*l*h)")
|
| 133 | + | read() |
| 134 | chestsAvailable = false | |
| 135 | - | nextTurnRight = true |
| 135 | + | end |
| 136 | - | h = 1 |
| 136 | + | |
| 137 | if turtle.getItemCount(15) > 0 then | |
| 138 | torchesAvailable = true | |
| 139 | - | w = 1 |
| 139 | + | torchSlot = 15 |
| 140 | - | while w <= width do |
| 140 | + | elseif turtle.getItemCount(16) > 0 then |
| 141 | - | print("")
|
| 141 | + | torchesAvailable = true |
| 142 | - | l = 1 |
| 142 | + | torchSlot = 16 |
| 143 | - | while l < length do |
| 143 | + | else |
| 144 | - | move() |
| 144 | + | torchesAvailable = false |
| 145 | - | l = l+1 |
| 145 | + | end |
| 146 | ||
| 147 | - | if w < width then |
| 147 | + | if turtle.getItemCount(14) > 0 then |
| 148 | - | if nextTurnRight then |
| 148 | + | chestsAvailable = true |
| 149 | - | t.right() |
| 149 | + | else |
| 150 | - | move() |
| 150 | + | chestsAvailable = false |
| 151 | - | t.right() |
| 151 | + | end |
| 152 | - | nextTurnRight = false |
| 152 | + | |
| 153 | - | else |
| 153 | + | x = 0 |
| 154 | - | t.left() |
| 154 | + | |
| 155 | - | move() |
| 155 | + | |
| 156 | - | t.left() |
| 156 | + | x = x + 1 |
| 157 | - | nextTurnRight = true |
| 157 | + | y = math.ceil(x*factor) |
| 158 | - | end |
| 158 | + | |
| 159 | for i = 1, y do | |
| 160 | - | w = w+1 |
| 160 | + | move() |
| 161 | - | end |
| 161 | + | if i%7 == 0 and y-i > 5 and torchesAvailable and turtle.detectDown() then |
| 162 | - | if h < height then |
| 162 | + | t.turnAround() |
| 163 | - | h = h+2 |
| 163 | + | turtle.select(torchSlot) |
| 164 | ||
| 165 | - | if h == height then |
| 165 | + | turtle.place() |
| 166 | - | h = h+1 |
| 166 | + | t.turnAround() |
| 167 | ||
| 168 | if torchSlot == 15 and turtle.getItemCount(torchSlot) == 0 then | |
| 169 | - | if h < height then |
| 169 | + | torchSlot = 16 |
| 170 | - | t.turnAround() |
| 170 | + | elseif torchSlot == 16 and turtle.getItemCount(torchSlot) == 0 then |
| 171 | - | t.up() |
| 171 | + | torchSlot = 15 |
| 172 | - | t.digUp() |
| 172 | + | end |
| 173 | - | if h < height then |
| 173 | + | |
| 174 | - | t.up() |
| 174 | + | if turtle.getItemCount(15) + turtle.getItemCount(16) > 0 then |
| 175 | - | t.digUp() |
| 175 | + | torchesAvailable = true |
| 176 | else | |
| 177 | torchesAvailable = false | |
| 178 | - | until h >= height |
| 178 | + | end |
| 179 | end | |
| 180 | - | t.down(height-2) |
| 180 | + | |
| 181 | - | for slot = 1, 15 do |
| 181 | + | |
| 182 | if torchesAvailable then | |
| 183 | - | turtle.drop() |
| 183 | + | t.dig() |
| 184 | turtle.select(torchSlot) | |
| 185 | turtle.place() | |
| 186 | end | |
| 187 | ||
| 188 | t.right() | |
| 189 | ||
| 190 | print (y .. " / " .. limit .. "... fuel: " .. turtle.getFuelLevel()) | |
| 191 | until y >= limit | |
| 192 | print("Done")
| |
| 193 | end |