SHOW:
|
|
- or go back to the newest paste.
| 1 | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
| 2 | -- Name: DanielKermanStripMining (DKSM) -- | |
| 3 | -- Author: Daniel_Kerman -- | |
| 4 | -- Version: 1.0.1 -- | |
| 5 | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
| 6 | ||
| 7 | ||
| 8 | -- Initializing -- | |
| 9 | ||
| 10 | local rowsMined = {0}
| |
| 11 | local totalRows = {0}
| |
| 12 | local hallLength = {0}
| |
| 13 | - | local fuelNeeded = {0}
|
| 13 | + | local fuelNeeded = {-1}
|
| 14 | local fuelLevel = turtle.getFuelLevel() | |
| 15 | local fuelLimit = turtle.getFuelLimit() | |
| 16 | local startConfirmed = "No" | |
| 17 | local slot = turtle.getSelectedSlot() | |
| 18 | local itemSpace = turtle.getItemSpace() | |
| 19 | local torchCounter = 0 | |
| 20 | ||
| 21 | -- Declaring Functions -- | |
| 22 | ||
| 23 | function forward() -- Help from the user Foogles (http://www.computercraft.info/forums2/index.php?/user/46239-foogles/) -- THANK YOU FOR THIS BUG SOLUTION! | |
| 24 | local x = turtle.forward() | |
| 25 | if (x == false) then | |
| 26 | return forward() | |
| 27 | end | |
| 28 | end | |
| 29 | ||
| 30 | local function clear(column,row) | |
| 31 | term.clear() | |
| 32 | if column == nil and row == nil then | |
| 33 | column = 1 | |
| 34 | row = 1 | |
| 35 | elseif row == nil then | |
| 36 | row = 1 | |
| 37 | elseif column == nil then | |
| 38 | column = 1 | |
| 39 | end | |
| 40 | term.setCursorPos(column,row) | |
| 41 | end | |
| 42 | ||
| 43 | local function checkNumber(varToCheck) | |
| 44 | assert(type(varToCheck) == "number", "Program expected number. Got string or something else instead.") | |
| 45 | end | |
| 46 | ||
| 47 | local function fallingBlock() | |
| 48 | local success, data = turtle.inspect() | |
| 49 | local fBlocks = | |
| 50 | {
| |
| 51 | sand="minecraft:sand", | |
| 52 | gravel="minecraft:gravel", | |
| 53 | anvil="minecraft:anvil", | |
| 54 | dragon_egg="minecraft:dragon_egg" | |
| 55 | } | |
| 56 | if data.name==fBlocks.sand or data.name==fBlocks.gravel or data.name==fBlocks.anvil or data.name==fBlocks.dragon_egg then | |
| 57 | return true | |
| 58 | else | |
| 59 | return false | |
| 60 | end | |
| 61 | end | |
| 62 | ||
| 63 | local function dig(length,back) | |
| 64 | for i=1, length do | |
| 65 | torchCounter=torchCounter+1 | |
| 66 | while fallingBlock() == true do | |
| 67 | turtle.dig() | |
| 68 | sleep(1) | |
| 69 | end | |
| 70 | turtle.dig() | |
| 71 | forward() | |
| 72 | turtle.digDown() | |
| 73 | if torchCounter >= 8 then | |
| 74 | turtle.select(16) | |
| 75 | if turtle.getItemSpace() < 64 then | |
| 76 | local data = turtle.getItemDetail() | |
| 77 | if data.name == "minecraft:torch" then | |
| 78 | turtle.placeDown() | |
| 79 | end | |
| 80 | end | |
| 81 | torchCounter = 0 | |
| 82 | turtle.select(1) | |
| 83 | end | |
| 84 | end | |
| 85 | if back == true then | |
| 86 | turtle.turnLeft() | |
| 87 | turtle.turnLeft() | |
| 88 | for i=2, length do | |
| 89 | forward() | |
| 90 | end | |
| 91 | forward() | |
| 92 | turtle.turnLeft() | |
| 93 | turtle.turnLeft() | |
| 94 | end | |
| 95 | ||
| 96 | end | |
| 97 | ||
| 98 | -- Welcome + User input -- | |
| 99 | ||
| 100 | clear(1,1) | |
| 101 | ||
| 102 | print("Welcome to the Strip Mining Program.")
| |
| 103 | sleep(1) | |
| 104 | print("Please enter a Hall/Strip Length (x = x block/s): ")
| |
| 105 | hallLength[1] = io.read() | |
| 106 | hallLength[1] = tonumber(hallLength[1]) | |
| 107 | checkNumber(hallLength[1]) | |
| 108 | print("Please enter a number of rows:")
| |
| 109 | totalRows[1] = io.read() | |
| 110 | totalRows[1] = tonumber(totalRows[1]) | |
| 111 | checkNumber(totalRows[1]) | |
| 112 | print("Calculating if turtle has enough fuel...")
| |
| 113 | fuelNeeded[1] = (hallLength[1]*3*totalRows[1])+(12*totalRows[1]) | |
| 114 | sleep(1.0) | |
| 115 | - | assert(fuelNeeded[1]<fuelLimit, "Your fuel Limit is too low. Try an advanced turtle.") |
| 115 | + | |
| 116 | - | assert(fuelNeeded[1]<fuelLevel, "Your turtle hasn't enought fuel.") |
| 116 | + | |
| 117 | clear(1,1) | |
| 118 | print("Place a chest behind the turtle.")
| |
| 119 | print("Place Torches to place in Slot 16 (Bottom right hand corner)")
| |
| 120 | write("Press any key to start the program.")
| |
| 121 | local skip = io.read() | |
| 122 | ||
| 123 | -- Post initialization -- | |
| 124 | ||
| 125 | local rowsToMine = totalRows[1]-rowsMined[1] | |
| 126 | clear(1,1) | |
| 127 | turtle.select(1) | |
| 128 | ||
| 129 | -- Main Loop -- | |
| 130 | ||
| 131 | for i=1, totalRows[1] do | |
| 132 | turtle.select(1) | |
| 133 | dig(3,false) | |
| 134 | turtle.turnLeft() | |
| 135 | dig(hallLength[1],true) | |
| 136 | rowsMined[1] = rowsMined[1]+1 | |
| 137 | clear(1,1) | |
| 138 | print("Rows Mined: ",rowsMined[1])
| |
| 139 | local z = 1 | |
| 140 | turtle.select(15) | |
| 141 | if turtle.getItemSpace() < 64 then | |
| 142 | turtle.turnLeft() | |
| 143 | for i=1,rowsMined[1]*3+1 do | |
| 144 | forward() | |
| 145 | end | |
| 146 | for i=1,15 do | |
| 147 | turtle.select(z) | |
| 148 | z=z+1 | |
| 149 | turtle.drop(64) | |
| 150 | end | |
| 151 | turtle.turnRight() | |
| 152 | turtle.turnRight() | |
| 153 | for i=1,rowsMined[1]*3+1 do | |
| 154 | forward() | |
| 155 | end | |
| 156 | turtle.turnLeft() | |
| 157 | end | |
| 158 | turtle.turnRight() | |
| 159 | rowsToMine = totalRows[1]-rowsMined[1] | |
| 160 | end | |
| 161 | ||
| 162 | -- Ending -- | |
| 163 | ||
| 164 | do | |
| 165 | print("Putting Items into chest.")
| |
| 166 | turtle.turnLeft() | |
| 167 | turtle.turnLeft() | |
| 168 | for i=1, (rowsMined[1]*3)+1 do | |
| 169 | forward() | |
| 170 | end | |
| 171 | z=1 | |
| 172 | for i=1,16 do | |
| 173 | turtle.select(z) | |
| 174 | z=z+1 | |
| 175 | turtle.drop(64) | |
| 176 | end | |
| 177 | end | |
| 178 | ||
| 179 | turtle.select(1) | |
| 180 | ||
| 181 | print("Mining Complete.")
| |
| 182 | ||
| 183 | sleep(2) | |
| 184 | ||
| 185 | clear(1,1) |