Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ***********
- * flatMining
- *
- * mine in shape of a flat space.
- * slot1~5 = ore
- * slot6 = chest, slot7,8 = torch *
- * slot9 = ironOre, slot10 = goldOre
- *
- **********
- ]]
- -- get arguments.
- local tArgs = { ... }
- -- define vars.
- local depth = tArgs[1]
- local width = tArgs[2]
- local side = 16
- local oreSlot1 = 1
- local oreSlot2 = 2
- local oreSlot3 = 3
- local oreSlot4 = 4
- local oreSlot5 = 5
- local ironSlot = 6
- local goldSlot = 7
- local chestSlot = 8
- local torchSlot1 = 9
- local torchSlot2 = 10
- local torchSlot3 = 11
- local torchSlot4 = 12
- --define functions.
- function mineStraight(line)
- local residue = depth*side-2
- local height = 1
- while residue > 0 do
- if compare('down') then
- dig('down')
- end
- if compare('up') then
- dig('up')
- end
- drop()
- torch(line, residue)
- if turtle.detect() == false then
- move('front')
- residue = residue - 1
- elseif compare('front') then
- dig('front')
- move('front')
- residue = residue - 1
- else
- dig('up')
- move('up')
- height = height + 1
- residue, height = detour(residue, height)
- end
- end
- while height > 1 do
- dig('down')
- move('down')
- height = height - 1
- end
- if compare('down') then
- dig('down')
- end
- if compare('up') then
- dig('up')
- end
- dig('front')
- move('front')
- end
- function compare(dir)
- local currentFunc = turtle.compare
- if dir == 'up' then
- currentFunc = turtle.compareUp
- elseif dir == 'down' then
- currentFunc = turtle.compareDown
- end
- local flag = false
- turtle.select(oreSlot1)
- flag = currentFunc()
- if flag == false then
- turtle.select(oreSlot2)
- flag = currentFunc()
- end
- if flag == false then
- turtle.select(oreSlot3)
- flag = currentFunc()
- end
- if flag == false then
- turtle.select(oreSlot4)
- flag = currentFunc()
- end
- if flag == false then
- turtle.select(oreSlot5)
- flag = currentFunc()
- end
- if flag == false then
- turtle.select(chestSlot)
- flag = currentFunc()
- end
- turtle.select(1)
- if flag == true then
- return false
- else
- return true
- end
- end
- function detour(residue, height)
- while compare('front') == false and turtle.detect() == true do
- dig('up')
- move('up')
- height = height + 1
- end
- dig('front')
- move('front')
- residue = residue -1
- if residue == 0 then
- return residue, height
- end
- while height > 1 do
- if compare('front') == false and turtle.detect() == true then
- while compare('front') == false and turtle.detect() == true do
- dig('up')
- move('up')
- height = height + 1
- end
- dig('front')
- move('front')
- residue = residue - 1
- elseif compare('front') or turtle.detect() == false then
- dig('front')
- move('front')
- residue = residue - 1
- while compare('down') or turtle.detectDown() == false do
- dig('down')
- move('down')
- height = height - 1
- if height == 1 then
- return residue, height
- end
- end
- end
- if residue == 0 then
- return residue, height
- end
- end
- return residue, height
- end
- function turn(dir)
- if compare('down') then
- dig('down')
- end
- if compare('up') then
- dig('up')
- end
- local currentFunc
- if dir%2 == 0 then
- currentFunc = turtle.turnLeft
- else
- currentFunc = turtle.turnRight
- end
- currentFunc()
- dig('front')
- move('front')
- currentFunc()
- end
- function drop()
- if turtle.getItemCount(16) ~= 0 then
- for i=10, 12, 1 do
- turtle.select(i)
- if turtle.compareTo(ironSlot) == false and turtle.compareTo(goldSlot) == false and turtle.compareTo(torchSlot1) == false then
- turtle.drop()
- end
- end
- for i=13, 16, 1 do
- turtle.select(i)
- if turtle.compareTo(ironSlot) == false and turtle.compareTo(goldSlot) == false then
- turtle.drop()
- end
- end
- end
- if turtle.getItemCount(16) ~= 0 then
- turtle.select(chestSlot)
- if turtle.placeDown() then
- turtle.select(ironSlot)
- turtle.dropDown(turtle.getItemCount(ironSlot)-1)
- turtle.select(goldSlot)
- turtle.dropDown(turtle.getItemCount(goldSlot)-1)
- for i=10, 12, 1 do
- turtle.select(i)
- if turtle.compareTo(torchSlot1) == false then
- turtle.dropDown()
- end
- end
- for i=13, 16, 1 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- turtle.select(1)
- end
- function dig(dir)
- local currentDig = turtle.dig
- local currentDetect = turtle.detect
- if dir == 'up' then
- currentDig = turtle.digUp
- currentDetect = turtle.detectUp
- elseif dir == 'down' then
- currentDig = turtle.digDown
- currentDetect = turtle.detectDown
- end
- local times = 0
- while currentDetect() do
- currentDig()
- times = times + 1
- if times == 15 then
- break
- end
- sleep(1)
- end
- end
- function move(dir)
- local currentMove = turtle.forward
- local currentAttack = turtle.attack
- if dir == 'up' then
- currentMove = turtle.up
- currentAttack = turtle.attackUp
- elseif dir == 'down' then
- currentMove = turtle.down
- currentAttack = turtle.attackDown
- end
- local times = 0
- while currentMove() == false do
- currentAttack()
- times = times + 1
- if times == 15 then
- return false
- end
- end
- return true
- end
- function torch(line, residue)
- if (line-3)%7 ~= 0 or residue%7 ~= 0 then
- return
- end
- if turtle.getItemCount(torchSlot1) == 1 then
- return
- end
- turtle.select(torchSlot1)
- if turtle.compareTo(torchSlot4) then
- turtle.select(torchSlot4)
- elseif turtle.compareTo(torchSlot3) then
- turtle.select(torchSlot3)
- elseif turtle.compareTo(torchSlot2) then
- turtle.select(torchSlot2)
- end
- turtle.placeDown()
- turtle.select(1)
- end
- --main thread.
- for i=1, width*side-1, 1 do
- print('start line'..i..'.')
- mineStraight(i)
- turn(i+1)
- end
- mineStraight(depth*side)
- dig('up')
- dig('down')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement