Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x,y,z = 0,0
- dir = { [0]="-Y", [1]="+X", [2]="+Y", [3]="-X", [4]="-Y", [4]="+X" }
- nDir = 1
- cID = 60
- rednet.open("right")
- sr = peripheral.wrap("left")
- function send(msg)
- rednet.send(cID,msg)
- 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 goFor()
- if turtle.forward() then
- goDirFor(true)
- return true
- else
- return false
- end
- end
- function goBack()
- if turtle.back() then
- goDirFor(false)
- return true
- else
- return false
- end
- end
- function goUp()
- return turtle.up()
- end
- function goDown()
- return turtle.down()
- 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 turnTo(str)
- while dir[nDir] ~= str do
- if dir[nDir+1] == str then
- turnRight()
- elseif dir[nDir-1] == str then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- function goTo(dx,dy)
- if x < dx then
- turnTo("+X")
- else
- turnTo("-X")
- end
- while x ~= dx do
- goFor()
- end
- if y < dy then
- turnTo("+Y")
- else
- turnTo("-Y")
- end
- while y ~= dy do
- goFor()
- end
- turnTo("+X")
- end
- function readSign()
- return sr.readUp()
- end
- function getItem()
- turnLeft()
- goFor()
- turtle.select(15)
- turtle.suckUp()
- turtle.select(16)
- turtle.suckUp()
- goFor()
- goUp()
- goUp()
- goBack()
- if turtle.getItemCount(16) == 1 then
- turtle.dropDown()
- else
- turtle.dropDown()
- turtle.select(15)
- turtle.dropDown()
- end
- goFor()
- goDown()
- goDown()
- goBack()
- goBack()
- turnRight()
- end
- getItem()
Advertisement
Add Comment
Please, Sign In to add comment