Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Floor Layer 0.1")
- print("Lays floor between all walls")
- print("It will keep going forward if")
- print("no walls are detected")
- print("")
- print("Fuel level:"..turtle.getFuelLevel())
- local DEBUG=false
- print("Currnet Position from home:")
- print("X="..x.." Y="..y.." Dir="..dir)
- print("Rest Home position? y/n")
- if (read()=="y") then
- x=0
- y=0
- end
- back=false
- finished=false
- --track direction facing
- --F=0 R=1 B=2 L=3
- dir=0
- local cx=0
- local cy=0
- local cdir=0
- turtle.select(1)
- slot=1
- function PlaceBlock()
- if not turtle.detectDown() then
- if turtle.getItemCount(slot) > 0 then
- turtle.placeDown()
- else
- stock=false
- for i=1,16 do
- if turtle.getItemCount(i)>0 then
- turtle.select(i)
- slot=i
- stock=true
- turtle.placeDown()
- break
- end
- end
- if stock == false then
- print("Calling returnHome()")
- local cx=x
- local cy=y
- local cdir=dir
- GoTo(0,0,0)
- Restock()
- if CheckStock() then
- print("No Materials left")
- exit()
- end
- GoTo(cx,cy,cdir)
- Turtle.placeDown()
- end
- end
- end
- end
- function TurnLeft()
- print("TurnLeft() Called")
- DebugPosition()
- turtle.turnLeft()
- dir=(dir-1)%4
- end
- function TurnRight()
- DebugPosition()
- turtle.turnRight()
- dir=(dir+1)%4
- end
- function MoveForward()
- DebugPosition()
- if turtle.forward() then
- if dir==0 then
- x=x+1
- elseif dir==1 then
- y=y+1
- elseif dir==2 then
- x=x-1
- elseif dir==3 then
- y=y-1
- else
- print("ERROR: Undefined direction")
- end
- end
- end
- function Turn(MyDir)
- while MyDir~=dir do
- if ((dir-MyDir)%4)==1 then
- TurnLeft()
- else
- TurnRight()
- end
- end
- end
- function GoTo(gx,gy,gdir)
- --print("Moving X")
- if (gx-x) > 0 then
- Turn(0)
- elseif (gx-x) < 0 then
- Turn(2)
- end
- while x~=gx do
- MoveForward()
- end
- --print("Moving Y")
- if (gy-y) > 0 then
- Turn(1)
- elseif (gy-y) < 0 then
- Turn(3)
- end
- while y~=gy do
- MoveForward()
- end
- Turn(gdir)
- end
- function NextBlock()
- if not turtle.detect() then
- MoveForward()
- else
- if dir==0 then
- TurnRight()
- if turtle.detect() then
- print("That was the last row")
- finished=true
- else
- MoveForward()
- TurnRight()
- end
- else
- TurnLeft()
- if turtle.detect() then
- print("That was the last row")
- finished=true
- else
- MoveForward()
- TurnLeft()
- end
- end
- end
- end
- function Restock()
- local result=true
- while result do
- result=turtle.suckUp()
- end
- print(result)
- end
- function CheckStock()
- for i=1, 16 do
- if turtle.getItemCount()>0 then
- stock=true
- return true
- else
- stock=false
- return false
- end
- end
- end
- function DebugPosition()
- if DEBUG==true then
- print("x="..x.." y="..y.." dir="..dir)
- end
- end
- Restock()
- while ((finished==false) and (turtle.getFuelLevel() > (x+y+5))) do
- --print("Debug "..x.." "..y.." "..dir)
- --DebugPosition()
- --print("Call PlaceBlock()")
- PlaceBlock()
- --print("call NextBlock()")
- NextBlock()
- end
- GoTo(0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement