Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- TO-DO:
- - return back to chest
- - up/down dig
- - quarry(x,y,z)
- - throw items
- - print out location and reset monitor
- - min fuel reserve level
- --]]
- --[[
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: exc3 x y z" )
- return
- end
- --]]
- local xPos = 0
- local yPos = 0
- local zPos = 0
- local dir = 0
- local fuelLevel = turtle.getFuelLevel()
- local oldXPos = 0
- local oldYPos = 0
- local oldZPos = 0
- local oldDir = 0
- -- Movement - no fuel needed
- function left()
- if turtle.turnLeft() then
- dir = dir + 1
- if dir == 4 then
- dir = 0
- end
- return true
- else
- return false
- end
- end
- function right()
- if turtle.turnRight() then
- dir = dir - 1
- if dir == -1 then
- dir = 3
- end
- return true
- else
- return false
- end
- end
- -- Movement - fuel needed
- function moveDown()
- turtle.digDown()
- if turtle.down() then
- yPos = yPos+1
- return true
- else
- return false
- end
- end
- function moveUp()
- turtle.digUp()
- if turtle.up() then
- yPos = yPos-1
- return true
- else
- return false
- end
- end
- function moveForward()
- turtle.dig()
- if turtle.forward() then
- if dir == 0 then
- xPos=xPos+1
- elseif dir == 1 then
- zPos=zPos+1
- elseif dir == 2 then
- xPos=xPos-1
- elseif dir == 3 then
- zPos=zPos-1
- end
- end
- end
- function rotate(d)
- while dir ~= d do
- right()
- end
- end
- function goTo(x,y,z,d) -- x,y,z,direction
- if fuel() == true then -- fueling
- -- X coordinate
- if xPos > x then
- rotate(2)
- elseif xPos < x then
- rotate(0)
- end
- while xPos ~= x do
- moveForward()
- end
- -- Z coordinate
- if zPos > z then
- rotate(3)
- elseif zPos < z then
- rotate(1)
- end
- while zPos ~= z do
- moveForward()
- end
- -- Y coordinate
- if yPos < y then
- while yPos ~= y do
- moveDown()
- end
- elseif yPos > y then
- while yPos ~= y do
- moveUp()
- end
- end
- print("went")
- end
- end
- -- Fueling
- function fuel()
- local hasFuel = false
- if turtle.getFuelLevel() < 50 then
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.refuel(0) then -- if it's valid fuel
- hasFuel = true
- break
- end
- end
- if hasFuel == true then
- for j=1,turtle.getItemCount() do
- if turtle.getFuelLevel() ~= turtle.getFuelLimit() then
- turtle.refuel(1)
- end
- end
- else
- print("no fuel - going back")
- --goBack()
- end
- else
- hasFuel = true
- end
- return hasFuel
- end
- function goBack()
- oldXPos = xPos
- oldYPos = yPos
- oldZPos = zPos
- oldDir = dir
- end
- function test()
- shell.run("label","set","Zmiskol")
- term.clear()
- print("Start Fuel Level: ",fuelLevel)
- goTo(0,2,0,0)
- sleep(5)
- goTo(2,0,0,2)
- end
- test()
Add Comment
Please, Sign In to add comment