SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = {...}
| |
| 2 | local x = tonumber(tArgs[1]) | |
| 3 | local y = tonumber(tArgs[3]) | |
| 4 | local z = tonumber(tArgs[2]) | |
| 5 | local size = "" | |
| 6 | local fuel = turtle.getFuelLevel() | |
| 7 | local lane = 0 | |
| 8 | local startPos = 0 | |
| 9 | ||
| 10 | turtle.select(1) | |
| 11 | term.clear() | |
| 12 | term.setCursorPos(1, 1) | |
| 13 | term.setTextColor(colors.white) | |
| 14 | ||
| 15 | local function getStartPos() | |
| 16 | ||
| 17 | if x == 1 then | |
| 18 | if y % 2 == 0 then | |
| 19 | return 1 | |
| 20 | else | |
| 21 | return 4 | |
| 22 | end | |
| 23 | elseif z == 1 then | |
| 24 | if y % 2 == 0 then | |
| 25 | return 1 | |
| 26 | else | |
| 27 | return 2 | |
| 28 | end | |
| 29 | end | |
| 30 | ||
| 31 | if y % 2 == 0 then | |
| 32 | return 1 | |
| 33 | else | |
| 34 | if z % 2 == 0 then | |
| 35 | return 4 | |
| 36 | else | |
| 37 | return 3 | |
| 38 | end | |
| 39 | end | |
| 40 | ||
| 41 | return 1 | |
| 42 | ||
| 43 | end | |
| 44 | ||
| 45 | local function digx() --Dig straight lines | |
| 46 | for f = 1,x do | |
| 47 | turtle.dig() | |
| 48 | while not turtle.forward() do | |
| 49 | turtle.dig() | |
| 50 | end | |
| 51 | end | |
| 52 | end | |
| 53 | ||
| 54 | local function changeLane() --Change lane when digging | |
| 55 | ||
| 56 | if lane == 0 then --If lane=0 turn right | |
| 57 | turtle.turnRight() | |
| 58 | turtle.dig() | |
| 59 | while not turtle.forward() do | |
| 60 | turtle.dig() | |
| 61 | end | |
| 62 | turtle.turnRight() | |
| 63 | lane = 1 | |
| 64 | return | |
| 65 | end | |
| 66 | ||
| 67 | if lane == 1 then --If lane=1 turn left | |
| 68 | turtle.turnLeft() | |
| 69 | turtle.dig() | |
| 70 | while not turtle.forward() do | |
| 71 | turtle.dig() | |
| 72 | end | |
| 73 | turtle.turnLeft() | |
| 74 | lane = 0 | |
| 75 | return | |
| 76 | end | |
| 77 | ||
| 78 | end | |
| 79 | ||
| 80 | local function goUp() --Go up to next layer | |
| 81 | while not turtle.up() do | |
| 82 | turtle.digUp() | |
| 83 | end | |
| 84 | turtle.turnRight() | |
| 85 | turtle.turnRight() | |
| 86 | end | |
| 87 | ||
| 88 | local function backToStart() --Go back to starting position when finished | |
| 89 | ||
| 90 | for f = 1,y do | |
| 91 | turtle.down() | |
| 92 | end | |
| 93 | if startPos == 1 then | |
| 94 | turtle.turnRight() | |
| 95 | turtle.turnRight() | |
| 96 | elseif startPos == 2 then | |
| 97 | for b = 1,x do | |
| 98 | turtle.back() | |
| 99 | end | |
| 100 | elseif startPos == 3 then | |
| 101 | turtle.turnRight() | |
| 102 | for c = 1, z do | |
| 103 | turtle.back() | |
| 104 | end | |
| 105 | turtle.turnLeft() | |
| 106 | for d = 1,x do | |
| 107 | turtle.back() | |
| 108 | end | |
| 109 | elseif startPos == 4 then | |
| 110 | turtle.turnRight() | |
| 111 | for e = 1,z do | |
| 112 | turtle.forward() | |
| 113 | end | |
| 114 | turtle.turnRight() | |
| 115 | end | |
| 116 | ||
| 117 | end | |
| 118 | ||
| 119 | local function checkArgs() --Check if arguments provided by the user are correct | |
| 120 | ||
| 121 | if #tArgs ~= 3 then | |
| 122 | return false | |
| 123 | end | |
| 124 | ||
| 125 | for a = 1,3 do | |
| 126 | if tonumber(tArgs[a]) == nil then | |
| 127 | return false | |
| 128 | end | |
| 129 | end | |
| 130 | ||
| 131 | if x < 1 or y < 1 or z < 1 then | |
| 132 | return false | |
| 133 | end | |
| 134 | ||
| 135 | return true | |
| 136 | ||
| 137 | end | |
| 138 | ||
| 139 | if not checkArgs() then --If arguments are not correct print an error message | |
| 140 | term.setTextColor(colors.red) | |
| 141 | print("Invalid arguments!")
| |
| 142 | term.setTextColor(colors.white) | |
| 143 | print("Specify size of the room like this:")
| |
| 144 | term.write("rooms")
| |
| 145 | term.setTextColor(colors.blue) | |
| 146 | print(" lenght width height")
| |
| 147 | return | |
| 148 | end | |
| 149 | ||
| 150 | size = x * y * z | |
| 151 | ||
| 152 | startPos = getStartPos() | |
| 153 | ||
| 154 | if fuel - size <= 0 then --Check if there is enough fuel | |
| 155 | term.setTextColor(colors.orange) | |
| 156 | print("Not enough fuel!")
| |
| 157 | return | |
| 158 | end | |
| 159 | ||
| 160 | x = x - 1 | |
| 161 | y = y - 1 | |
| 162 | z = z - 1 | |
| 163 | ||
| 164 | print("Digging...")
| |
| 165 | for j = 1,y do | |
| 166 | for i = 1,z do | |
| 167 | digx() | |
| 168 | changeLane() | |
| 169 | end | |
| 170 | digx() | |
| 171 | goUp() | |
| 172 | end | |
| 173 | ||
| 174 | for k = 1,z do | |
| 175 | digx() | |
| 176 | changeLane() | |
| 177 | end | |
| 178 | digx() | |
| 179 | backToStart() | |
| 180 | print("Done!")
| |
| 181 | x = x + 1 | |
| 182 | y = y + 1 | |
| 183 | z = z + 1 | |
| 184 | print(size, "blocks cleared") |