Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y,z,dir=0,0,0,0
- local fuelSlot=1
- function refuel()
- turtle.select(fuelSlot)
- turtle.refuel(1)
- end
- function forward()
- reussit=turtle.forward()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.dig()
- end
- reussit=turtle.forward()
- end
- if reussit 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
- end
- end
- return reussit
- end
- function back()
- reussit=turtle.back()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- end
- reussit=turtle.back()
- end
- if reussit 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
- end
- end
- return reussit
- end
- function up()
- reussit=turtle.up()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.digUp()
- end
- reussit=turtle.up()
- end
- if reussit then
- z=z+1
- end
- return reussit
- end
- function down()
- reussit=turtle.down()
- if not reussit then
- if turtle.getFuelLevel()==0 then
- refuel()
- else
- turtle.digDown()
- end
- reussit=turtle.down()
- end
- if reussit then
- z=z-1
- end
- return reussit
- end
- function turnRight()
- turtle.turnRight()
- dir=(dir+1)%4
- end
- function turnLeft()
- turtle.turnLeft()
- dir=dir-1
- if dir==-1 then
- dir=0
- end
- end
- function setDir(d)
- dif=dir-d
- if math.abs(dif)>2 then
- if dif>0 then
- dif=dif-4
- else
- dif=dif+4
- end
- end
- print(dif)
- while dir~=d do
- print(dir)
- if dif>0 then
- turnLeft()
- else
- turnRight()
- end
- end
- end
- function reset()
- x,y,z,dir=0,0,0,0
- end
- function setFuelSlot(s)
- fuelSlot=s
- end
- function getPosition()
- return x,y,z,dir
- end
- function setPosition(px,py,pz,pdir)
- x,y,z,dir=px,py,pz,pdir
- end
- function getDir()
- return dir
- end
- function setDir(d)
- dir=d
- end
- function getX()
- return x
- end
- function getY()
- return y
- end
- function getZ()
- return z
- end
- function setX(p)
- x=p
- end
- function setY(p)
- y=p
- end
- function setZ(p)
- z=p
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement