Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Args = {...}
- x,y = 0,0
- dir = { [1]="+X", [2]="+Y", [3]="-X", [4]="-Y" }
- nDir = 1
- function printUsage()
- print("Usage:")
- print("strip <BLOCKS> <WIDE> <left/right>")
- print("Strip mines <BLOCKS> blocks infront and <WIDE> blocks to the side.")
- end
- function printFail()
- print("Failed at a task.")
- end
- function hasSpace()
- local space = false
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- space = true
- end
- end
- return space
- end
- function getFuel()
- return turtle.getFuelLevel()
- end
- function hasFuel()
- if getFuel() == 0 then
- return false
- else
- return true
- end
- end
- function dropOff()
- print("Dropping off items, fuel: "..getFuel())
- turtle.digDown()
- turtle.select(1)
- if turtle.placeDown() then
- for i=2,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- turtle.digDown()
- end
- end
- function goDirFor(bool)
- if bool then
- if dir[nDir] == "+X" then x = x + 1 elseif
- dir[nDir] == "-X" then x = x - 1 elseif
- dir[nDir] == "+Y" then y = y + 1 elseif
- dir[nDir] == "-Y" then y = y - 1 end
- else
- if dir[nDir] == "+X" then x = x - 1 elseif
- dir[nDir] == "-X" then x = x + 1 elseif
- dir[nDir] == "+Y" then y = y - 1 elseif
- dir[nDir] == "-Y" then y = y + 1 end
- end
- end
- function mineFor()
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- if not hasSpace() then dropOff() end
- return true
- end
- function mineUp()
- while detectUp() do
- turtle.digUp()
- os.sleep(0.5)
- end
- if not hasSpace() then dropOff() end
- return true
- end
- function mineDown()
- turtle.digDown()
- if not hasSpace() then dropOff() end
- return true
- end
- function goFor()
- if turtle.forward() then
- goDirFor(true)
- else
- return false
- end
- end
- function goBack()
- if turtle.back() then
- goDirFor(false)
- else
- return false
- end
- end
- function turnRight()
- turtle.turnRight()
- if nDir < 4 then
- nDir = nDir + 1
- else
- nDir = 1
- end
- end
- function turnLeft()
- turtle.turnLeft()
- if nDir > 1 then
- nDir = nDir - 1
- else
- nDir = 4
- end
- end
- function detectFor()
- return turtle.detect()
- end
- function detectUp()
- return turtle.detectUp()
- end
- function detectDown()
- return turtle.detectDown()
- end
- function mine()
- mineFor()
- mineUp()
- mineDown()
- goFor()
- end
- function stripFor()
- if dirFor then
- while x < blocksfor do
- mineFor()
- mineUp()
- mineDown()
- goFor()
- end
- else
- while x > 0 do
- mineFor()
- mineUp()
- mineDown()
- goFor()
- end
- end
- end
- function resetPos()
- while dir[nDir] ~= "-X" do
- turnRight()
- end
- while x ~= 0 do
- goFor()
- end
- if y < 0 then
- while dir[nDir] ~= "+Y" do
- turnLeft()
- end
- else
- while dir[nDir] ~= "-Y" do
- turnLeft()
- end
- end
- while y ~= 0 do
- goFor()
- end
- if dir[nDir] == "+Y" then
- turnRight()
- elseif dir[nDir] == "-Y" then
- turnLeft()
- end
- end
- function stripMine(num)
- for i=1,num do
- stripFor()
- if i < num then
- print("Turning around, fuel: "..getFuel())
- if boolTurnRight then
- turnRight()
- mine()
- turnRight()
- else
- turnLeft()
- mine()
- turnLeft()
- end
- boolTurnRight = not boolTurnRight
- dirFor = not dirFor
- end
- end
- mineUp()
- mineDown()
- print("Going back to start, fuel: "..getFuel())
- resetPos()
- dropOff()
- print("Job done, fuel: "..getFuel())
- end
- if #Args == 0 then
- printUsage()
- else
- if tonumber(Args[1]) == 0 or tonumber(Args[2]) == 0 then
- printUsage()
- else
- if Args[3] == "right" or Args[3] == "left" then
- if Args[3] == "right" then
- boolTurnRight = true
- else
- boolTurnRight = false
- end
- blocksfor = tonumber(Args[1]) - 1
- dirFor = true
- stripMine(tonumber(Args[2]))
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment