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
- --]]
- -- Position Variables
- local xPos = 0
- local yPos = 0
- local zPos = 0
- local dir = 0
- local oldXPos = 0
- local oldYPos = 0
- local oldZPos = 0
- local oldDir = 0
- --Fuel Variables
- local fuelLevel = turtle.getFuelLevel()
- local coalCount = 0
- local coalIndex = 1
- -- 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()
- if Math.fmod(xPos,10) == 0 then
- fuel()
- end
- end
- -- Z coordinate
- if zPos > z then
- rotate(3)
- elseif zPos < z then
- rotate(1)
- end
- while zPos ~= z do
- moveForward()
- if Math.fmod(yPos,10) == 0 then
- fuel()
- end
- end
- -- Y coordinate
- if yPos < y then
- while yPos ~= y do
- moveDown()
- if Math.fmod(yPos,10) == 0 then
- fuel()
- end
- end
- elseif yPos > y then
- while yPos ~= y do
- moveUp()
- if math.fmod(yPos,10) == 0 then
- fuel()
- end
- end
- end
- -- Rotation
- rotate(d)
- end
- end
- -- Distance
- function distBase()
- local sum = math.abs(xPos)+math.abs(zPos)+math.abs(yPos)
- return sum
- end
- -- Pickup
- function pickUp()
- if turtle.getItemCount(1) ~= 0 then
- turtle.select(1)
- turtle.suck()
- turtle.suckDown()
- turtle.suckUp()
- else
- turtle.select(2)
- turtle.suck()
- turtle.suckDown()
- turtle.suckUp()
- end
- end
- -- Fueling
- function checkFuel()
- local hasFuel = false
- local maxCoal = 0
- local maxCoalSlot = 1
- for i = 1, 16 do -- loop through the slots
- turtle.select(i) -- change to the slot
- if turtle.getItemDetail().name == "minecraft:coal" then
- hasFuel = true
- coalCount=coalCount+turtle.getItemCount()
- if maxCoal < turtle.getItemCount() then
- maxCoal = turtle.getItemCount()
- maxCoalSlot = i
- end
- end
- end
- return hasFuel
- end
- function fuel()
- if turtle.getFuelLevel() < 100 then
- if checkFuel() == true then
- turtle.select(maxCoalSlot)
- for i=1,turtle.getItemCount() do
- if turtle.getFuelLevel() ~= turtle.getFuelLimit() or turtle.getItemCount() ~= 0 then
- turtle.refuel(1)
- end
- end
- else
- print("not enough fuel - going back")
- goBase()
- end
- end
- end
- function goBase()
- oldXPos = xPos
- oldYPos = yPos
- oldZPos = zPos
- oldDir = dir
- goTo(0,0,0,0)
- end
- function test()
- shell.run("label","set","Zmiskol")
- term.clear()
- print("Start Fuel Level: ",fuelLevel)
- goTo(10,-10,10,0)
- print(turtle.getFuelLevel())
- goBase()
- print(turtle.getFuelLevel())
- end
- test()
Add Comment
Please, Sign In to add comment