Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local xPos, yPos, zPos = 0, 0, 0 --location zPos (bigger then zero is below startpoint and smaller then zero is above startpoint)
- local xSave, ySave, zSave, dirSave = 0, 0, 0, 0
- local direction = 0 --direction in for ways 0 is start position
- local al = true --alternate
- local al2 = true --alternate2
- local firsttime = true
- local length, width, height = 0, 0, 0
- local args={...}
- function main()
- if #args ~= 3 then
- print("ClearOut<height><width><length>")
- else
- length = tonumber(args[1])
- width = tonumber(args[2])
- height = tonumber(args[3])
- for z = 0, height - 1 do
- for x = 0, width - 1 do
- for y = 0, length - 2 do
- if firsttime then
- y = y + 1
- firsttime = false
- end
- Forward()
- end
- if x < length - 1 then
- if al then
- RightUTurn(true)
- al = false
- else
- LeftUTurn(true)
- al = true
- end
- end
- end
- if height > 0 then
- Down()
- else
- Up()
- end
- RightUTurn(false)
- if al2 then
- if direction == 0 then
- al = false
- else
- al = true
- end
- al2 = false
- else
- if direction == 0 then
- al = true
- else
- al = false
- end
- al2 = true
- end
- end
- end
- end
- function CheckFuel()
- local fuel = turtle.getFuelLevel()
- local level = xPos + yPos + math.abs(zPos) + 2
- if fuel > level then
- return true;
- else
- print("Taking new fuel from slot 1")
- if turtle.getItemCount(1) > 0 then
- turtle.select(1)
- if turtle.refuel(5) == false then
- print("No fuel in slot")
- SaveLocation()
- print("Going back to chest")
- Goto(0,0,0)
- if CheckChestFuel() == false then
- RightUTurn(false)
- error("No fuel in chest")
- end
- CheckFuel()
- RestoreLocation()
- end
- end
- end
- end
- function Forward()
- CheckFuel()
- while turtle.forward() == false do
- CheckInventory(0)
- turtle.select(2)
- turtle.dig()
- end
- if direction == 0 then
- yPos = yPos + 1
- elseif direction == 2 then
- yPos = yPos - 1
- elseif direction == 1 then
- xPos = xPos + 1
- else
- xPos = xPos - 1
- end
- end
- function Down()
- CheckFuel()
- while turtle.down() == false do
- CheckInventory(2)
- turtle.select(2)
- turtle.digDown()
- end
- zPos = zPos + 1
- end
- function Up()
- CheckFuel()
- while turtle.up() == false do
- CheckInventory(1)
- turtle.select(2)
- turtle.digUp()
- end
- zPos = zPos - 1
- end
- function Left(forward)
- turtle.turnLeft()
- SubstractDirection()
- if forward then
- Forward()
- end
- end
- function Right(forward)
- turtle.turnRight()
- AddDirection()
- if forward then
- Forward()
- end
- end
- function AddDirection()
- direction = direction + 1
- if direction > 3 then
- direction = 0
- end
- end
- function SubstractDirection()
- direction = direction - 1
- if direction < 0 then
- direction = 3
- end
- end
- function RightUTurn(forward)
- Right(forward)
- Right(false)
- end
- function LeftUTurn(forward)
- Left(forward)
- Left(false)
- end
- function Goto(xLoc, yLoc, zLoc)
- while zPos ~= zLoc do
- if zLoc > zPos then
- Up()
- else
- Down()
- end
- end
- while direction ~= 3 do
- if direction == 0 then
- Left(false)
- else
- Right(false)
- end
- end
- while xPos > xLoc do
- Forward()
- end
- Left()
- while yPos > yLoc do
- Forward()
- end
- end
- function ChangeDirection(dir)
- while direction ~= dir do
- Right(false)
- end
- end
- function SaveLocation()
- xSave, ySave, zSave, dirSave = xPos, yPos, zPos, direction
- end
- function RestoreLocation()
- Goto(xSave, ySave, zSave)
- ChangeDirection(dirSave)
- end
- function CheckInventory(check)
- if turtle.getItemCount(16) > 0 then
- if BlockFit(check) == false then
- print("Inventory is full")
- SaveLocation()
- print("Returning to chest...")
- Goto(0, 0, 0)
- print("Empty inventory")
- EmptyInventory()
- print("Restore location")
- RestoreLocation()
- end
- end
- end
- function BlockFit(check)
- for i = 1, 16 do
- if turtle.getItemSpace(i) > 0 then
- turtle.select(i)
- if check == 0 then
- if turtle.compare() then
- return true
- end
- elseif check == 1 then
- if turtle.compareUp() then
- return true
- end
- else
- if turtle.compareDown() then
- return true
- end
- end
- end
- end
- return false
- end
- function EmptyInventory()
- for i = 2, 16 do
- print("Emptying slot " .. i)
- if turtle.getItemCount(i) ~= 0 then
- turtle.select(i)
- if turtle.drop() == false then
- RightUTurn(false)
- error("Chest is full")
- end
- end
- end
- end
- function GetEmptySlot()
- for i = 2, 16 do
- if turtle.getItemCount(i) == 0 then
- return i
- end
- end
- return 0
- end
- function CheckChestFuel()
- local slot = GetEmptySlot()
- if slot == 0 then
- EmptyInventory()
- else
- turtle.select(slot)
- for i = 0, 10 do
- if turtle.suck() == false then
- RightUTurn(false)
- error("No fuel found")
- end
- if turtle.drop() == false then
- RightUTurn(false)
- error("Chest is full")
- end
- end
- CheckFuel()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement