Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- width = 3
- heigth = 2
- sleep_time = 0.5
- torch_slot = 16
- distance_moved = 0
- y_offset = 0
- torch_distance = 6
- blocks_mined = 0
- torch_id = "minecraft:torch"
- -- All orientation are relative to the initial placement of the turtle.
- -- Forward is considered as north.
- -- north = 1
- -- east = 2
- -- south = 3
- -- west = 4
- orientation = 1
- function BlockMined ()
- blocks_mined = blocks_mined + 1
- end
- function Dig ()
- while turtle.detect() do
- turtle.dig()
- BlockMined()
- os.sleep(sleep_time)
- end
- end
- function DigUp ()
- while turtle.detectUp() do
- turtle.digUp()
- BlockMined()
- os.sleep(sleep_time)
- end
- end
- function DigDown ()
- while turtle.detectDown() do
- turtle.digDown()
- BlockMined()
- os.sleep(sleep_time)
- end
- end
- function MoveX (distance)
- for i = 1, distance, 1 do
- turtle.forward()
- if orientation == 1 then
- distance_moved = distance_moved + 1
- elseif orientation == 3 then
- distance_moved = distance_moved - 1
- end
- end
- end
- function Move ()
- MoveX(1)
- end
- -- This function does the same as Move, but clears the way if it is obstructed.
- function MoveAndCheck ()
- if turtle.detect() then
- Dig()
- end
- Move()
- end
- -- This function does do the same as MoveX, but clears the way if it is obstructed.
- function MoveAndCheckX (distance)
- for i = 1, distance, 1 do
- MoveAndCheck()
- end
- end
- function Left ()
- turtle.turnLeft()
- if orientation == 1 then
- orientation = 4
- else
- orientation = orientation - 1
- end
- end
- function Right ()
- turtle.turnRight()
- if orientation == 4 then
- orientation = 1
- else
- orientation = orientation + 1
- end
- end
- function Reverse ()
- Right()
- Right()
- end
- function UpX (distance)
- for i = 1, distance, 1 do
- turtle.up()
- y_offset = y_offset + 1
- end
- end
- function Up ()
- UpX(1)
- end
- function UpAndCheck ()
- if turtle.detectUp() then
- DigUp()
- end
- Up()
- end
- function UpAndCheckX (distance)
- for i = 1, distance, 1 do
- UpAndCheck()
- end
- end
- function DownX (distance)
- for i = 1, distance, 1 do
- turtle.down()
- y_offset = y_offset - 1
- end
- end
- function Down ()
- DownX(1)
- end
- function DownAndCheck ()
- if turtle.detectDown() then
- DigDown()
- end
- Down()
- end
- function DownAndCheckX (distance)
- for i = 1, distance, 1 do
- DownAndCheck()
- end
- end
- function PlaceTorch ()
- Reverse()
- local prev_slot = turtle.getSelectedSlot()
- turtle.select(torch_slot)
- turtle.place()
- turtle.select(prev_slot)
- Reverse()
- end
- function UnloadInventory ()
- for i = 1, 15, 1 do
- turtle.select(i)
- if not turtle.drop() then
- print("Chest invntory full.\n")
- while not turtle.drop() do
- os.sleep(sleep_time * 10)
- end
- end
- end
- end
- function BackTrack ()
- if orientation == 1 then
- -- EAST (x)
- Right()
- if not turtle.detect() then
- Move()
- Right()
- MoveAndCheck()
- else
- -- WEST (x)
- Reverse()
- if not turtle.detect() then
- Move()
- Left()
- MoveAndCheck()
- Left()
- -- This is in case there's a torch in the way.
- if turtle.detect() then
- UpAndCheck()
- MoveAndCheckX(2)
- DownAndCheck()
- end
- MoveAndCheckX(2)
- Right()
- else
- -- SOUTH (x-1)
- Left()
- if not turtle.detect() then
- Move()
- Left()
- MoveAndCheck()
- Right()
- else
- UpAndCheck()
- MoveAndCheck()
- Left()
- MoveAndCheck()
- Right()
- end
- end
- end
- MoveAndCheckX(distance_moved)
- end
- end
- function DigYLayer ()
- DigUp()
- Up()
- Left()
- Dig()
- Reverse()
- Dig()
- Left()
- end
- function DigBottomLayer ()
- Dig()
- Move()
- Left()
- Dig()
- Reverse()
- Dig()
- Left()
- end
- function DigLayer ()
- DigBottomLayer()
- for i = 1, heigth - 1, 1 do
- DigYLayer()
- end
- DownX(y_offset)
- end
- function DigTunnel (distance)
- local distance_since_last_torch = 0
- for i = 1, distance, 1 do
- DigLayer()
- if distance_since_last_torch == torch_distance then
- PlaceTorch()
- end
- end
- BackTrack()
- end
- function Startup ()
- if arg[1] then
- distance = arg[1]
- else
- distance = 75
- end
- turtle.select(torch_slot)
- local _, data = turtle.getItemDetail()
- if data then
- if data.name == torch_id then
- local torches_needed = math.floor(distance / torch_distance)
- if data.count < math.floor(distance / torch_distance) then
- print(string.format("Please insert &d more torches and hit enter.\n",torches_needed - data.count))
- io.read()
- end
- end
- end
- DigTunnel(distance)
- end
- Startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement