Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a = {}
- local args = {...}
- local counter = 4
- local numbering = 5
- local posX = 0
- local posY = 0
- local posZ = 0
- posX, posY, posZ = gps.locate(5)
- local startX = posX
- local startY = posY
- local startZ = posZ
- local direction = 0
- local staticDirect = 0
- local startDirect = 0
- local inventory = 1
- function a.orient()
- turtle.forward()
- posX, posY, posZ = gps.locate(5)
- if posX-startX > 0 then
- direction = 0
- end
- if posZ-startZ > 0 then
- direction = 1
- end
- if posX-startX < 0 then
- direction = 2
- end
- if posX-startX < 0 then
- direction = 3
- end
- staticDirect = direction
- startDirect = direction
- end
- function a.threeXplus()
- for i=0, tonumber(args[1]) do
- counter = counter+1
- numbering = counter
- while numbering>4 do
- if numbering%2 == 0 then
- numbering = numbering/2
- a.buildDown()
- turtle.forward()
- turtle.turnLeft()
- staticDirect = staticDirect - 1
- turtle.forward()
- if tonumber(args[2]) == 1 then
- staticDirect = staticDirect + 1
- turtle.turnRight()
- end
- else
- numbering = numbering*3+1
- a.buildDown()
- turtle.forward()
- turtle.turnRight()
- staticDirect = staticDirect + 1
- turtle.forward()
- if tonumber(args[2]) == 1 then
- staticDirect = staticDirect - 1
- turtle.turnLeft()
- end
- end
- if staticDirect> 3 then
- staticDirect= 0
- end
- if staticDirect< 0 then
- staticDirect= 3
- end
- direction = staticDirect
- a.checkSupply()
- end
- end
- end
- function a.checkSupply()
- turtle.select(16)
- if turtle.getItemCount() < 10 then
- posX, posY, posZ = gps.locate(5)
- tempX = posX
- tempY = posY
- tempZ = posZ
- a.moveTo(startX,tempY,startZ)
- a.moveTo(startX,startY,startZ)
- a.rotateTo(startDirect)
- turtle.turnLeft()
- print("Not enough blocks")
- while turtle.getItemCount() <10 do
- turtle.suck()
- sleep(1)
- end
- turtle.turnRight()
- a.moveTo(startX,tempY,startZ)
- a.moveTo(tempX,tempY,tempZ)
- inventory = 1
- end
- turtle.select(inventory)
- if turtle.getFuelLevel() < 100 then
- posX, posY, posZ = gps.locate(5)
- tempX = posX
- tempY = posY
- tempZ = posZ
- a.moveTo(startX,tempY,startZ)
- a.moveTo(startX,startY,startZ)
- a.rotateTo(startDirect)
- turtle.turnRight()
- print("Not enough fuel")
- while turtle.getFuelLevel() < 100 do
- turtle.suck()
- turtle.refuel()
- sleep(1)
- end
- turtle.turnLeft()
- a.moveTo(startX,tempY,startZ)
- a.moveTo(tempX,tempY,tempZ)
- end
- end
- function a.buildDown()
- if turtle.getItemCount() >0 then
- inventory = inventory+1
- end
- if inventory > 16 then
- a.checkSupply()
- else
- turtle.select(inventory)
- turtle.placeDown()
- end
- end
- function a.moveTo(targetX,targetY,targetZ)
- posX, posY, posZ = gps.locate(5)
- while posY > targetY do
- turtle.down()
- end
- while posY < targetY do
- turtle.up()
- end
- if posX > targetX then
- a.rotateTo(2)
- end
- if posX < targetX then
- a.rotateTo(0)
- end
- while posX ~= targetX do
- turtle.forward()
- end
- if posZ > targetZ then
- a.rotateTo(3)
- end
- if posZ < targetZ then
- a.rotateTo(1)
- end
- while posZ ~= targetZ do
- turtle.forward()
- end
- end
- function a.rotateTo(targetD)
- while direction ~= targetD
- if direction > 3 then
- direction = 0
- end
- if direction < 0 then
- direction = 3
- end
- if direction < targetD then
- direction = direction + 1
- turtle.turnRight()
- end
- if direction > targetD then
- direction = direction - 1
- turtle.turnLeft()
- end
- end
- end
- --Start of program
- a.orient()
- a.threeXplus()
Add Comment
Please, Sign In to add comment