Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local zz=turtle
- local args = {...}
- local currentX=0 -- hoz
- local currentY=0 -- height
- local currentZ=0 -- depth
- local currRad=1 -- 0 is the right, 1 is default (original direction), 2 is the left, 3 is the back
- local cacheSlot = {}
- function place(slotID)
- for i=1,12 do
- zz.select(i)
- if zz.getItemCount()>0 then
- return zz.place()
- end
- end
- return false
- end
- function refuel(amount)
- while zz.getFuelLevel()<=math.abs(amount) do
- zz.select(16)
- zz.refuel(1)
- print("Refueling")
- end
- end
- function turnRight()
- while zz.turnRight() do
- currRad=(currRad-1)%4
- break
- end
- end
- function turnLeft()
- while zz.turnLeft() do
- currRad=(currRad+1)%4
- break
- end
- end
- function turnToRad(r)
- if currRad==r then
- return true
- end
- while currRad~=r do
- if currRad>r then
- turnRight()
- elseif currRad<r then
- turnLeft()
- end
- end
- end
- function alertForProblem(stringCauseOfProblem)
- zz.turnRight()
- zz.turnRight()
- zz.turnRight()
- zz.turnRight()
- print(stringCauseOfProblem)
- end
- function moveByX(ox)
- local x=currentX+ox
- turnToRad(0)
- refuel(ox)
- while ox~=0 do
- if ox<0 then
- if zz.back() then
- ox=ox+1
- currentX=currentX-1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByX(ox)
- break
- end
- else
- if zz.forward() then
- ox=ox-1
- currentX=currentX+1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByX(ox)
- break
- end
- end
- end
- end
- function moveByZ(oz)
- local z=currentZ+oz
- turnToRad(1)
- refuel(oz)
- while oz~=0 do
- if oz<0 then
- if zz.back() then
- oz=oz+1
- currentZ=currentZ-1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByZ(oz)
- break
- end
- else
- if zz.forward() then
- oz=oz-1
- currentZ=currentZ+1
- else
- alertForProblem("can not move - check fuel or obstacle")
- moveByZ(oz)
- break
- end
- end
- end
- end
- function moveByY(oy)
- local y=currentY+oy
- refuel(oy)
- while oy~=0 do
- if oy<0 then
- if zz.down() then
- oy=oy+1
- currentY=currentY-1
- else
- alertForProblem("can not move down - check fuel or obstacle")
- moveByY(oy)
- break
- end
- else
- if zz.up() then
- oy=oy-1
- currentY=currentY+1
- else
- alertForProblem("can not move up - check fuel or obstacle")
- moveByY(oy)
- break
- end
- end
- end
- end
- function goToCord(y,x,z)
- local differenceX=x-(currentX)
- local differenceY=y-currentY
- local differenceZ=z-currentZ
- if differenceX~=0 then moveByX(differenceX) end
- if differenceY~=0 then moveByY(differenceY) end
- if differenceZ~=0 then moveByZ(differenceZ) end
- end
- function placeAt(y,x,z,slotID)
- goToCord(y,x,z)
- if place(slotID) then return true
- else
- alertForProblem("can not place ahead - must be air ahead or do I have a material to place")
- placeAt(y,x,z,slotID)
- end
- end
- function progressionPlace(startAt)
- for i=1,206 do
- local result=placeAt(i-207,0,0,15)
- if result then print("Finished Task #"..i.." out of "..206) end
- end
- goToCord(0,0,0);
- end
- if (#args==1) then
- zz.select(15);
- zz.place();
- sleep(1);
- zz.place();
- goToCord(-208,0,0);
- progressionPlace(1);
- else
- while true do
- id,message=rednet.recieve();
- if id==3522 then
- zz.select(15);
- zz.place();
- sleep(1);
- zz.place();
- goToCord(-208,0,0);
- progressionPlace(1);
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement