Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local blacklist = {
- ["minecraft:bedrock"] = true,
- ["minecraft:stone"] = true,
- ["minecraft:cobblestone"] = true,
- ["minecraft:dirt"] = true,
- ["minecraft:grass"] = true,
- ["minecraft:gravel"] = true,
- ["minecraft:sand"] = true,
- ["minecraft:water"] = true,
- ["minecraft:flowing_water"] = true,
- ["minecraft:lava"] = true,
- ["minecraft:flowing_lava"] = true
- }
- local tArgs = {...}
- if #tArgs ~= 1 then
- print("Usage: ShaftMiner <distance>")
- return
- end
- local length = tonumber(tArgs[1])
- local dist = 0
- local dir = 0
- local function refuel()
- if turtle.getFuelLevel() < 100 then
- turtle.refuel(1)
- end
- end
- local function turn(to)
- local rel = (to + 4 - dir) % 4
- if rel == 1 then
- turtle.turnRight()
- elseif rel == 2 then
- turtle.turnRight()
- turtle.turnRight()
- elseif rel == 3 then
- turtle.turnLeft()
- end
- dir = to
- end
- local function reverse(to)
- if to < 4 then
- return (to + 2) % 4
- elseif to == 4 then
- return 5
- elseif to == 5 then
- return 4
- end
- end
- local function trymove(to)
- refuel()
- if to < 4 then
- turn(to)
- return turtle.forward()
- elseif to == 4 then
- return turtle.up()
- elseif to == 5 then
- return turtle.down()
- end
- end
- local function move(to)
- refuel()
- while not trymove(to) do end
- end
- local function dig(to)
- refuel()
- if to < 4 then
- turn(to)
- turtle.dig()
- elseif to == 4 then
- turtle.digUp()
- elseif to == 5 then
- turtle.digDown()
- end
- end
- local function moveDig(to)
- while not trymove(to) do dig(to) end
- end
- local function inspect(to)
- refuel()
- if to < 4 then
- turn(to)
- return turtle.inspect()
- elseif to == 4 then
- return turtle.inspectUp()
- elseif to == 5 then
- return turtle.inspectDown()
- end
- end
- local function unload()
- print("Unloading items...")
- for n=2,16 do
- turtle.select(n)
- turtle.drop()
- end
- turtle.select(1)
- print("Unloaded!")
- end
- local function checkFull()
- if turtle.getItemCount(16) > 0 then
- print("Inventory full, returning home...")
- return true
- else
- return false
- end
- end
- local function dropoff()
- for n=1,dist do move(2) end
- unload()
- for n=1,dist do move(0) end
- end
- local function mineVein()
- local n = 1
- local stack = {}
- while n > 0 do
- local cur = (stack[n] or -1) + 1
- stack[n] = cur
- if cur < 6 then
- local success, data = inspect(cur)
- if success and not blacklist[data.name] then
- moveDig(cur)
- n = n + 1
- end
- else
- stack[n] = nil
- n = n - 1
- if n > 0 then moveDig(reverse(stack[n])) end
- end
- if checkFull() then
- for i=n-1,1,-1 do moveDig(reverse(stack[i])) end
- dropoff()
- for i=1,n-1 do moveDig(stack[i]) end
- end
- end
- end
- while dist < length do
- moveDig(0)
- dist = dist + 1
- if checkFull() then dropoff() end
- mineVein()
- end
- print("Finished shaft, returning home!")
- for i=1,dist do move(2) end
- unload()
- turn(0)
- print("Finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement