Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- West = Negative x
- -- Top = Positive y
- -- North = Negative z
- local x,y,z = 0,0,0 --Relative to First position
- local Orien = 0 --0:Forward; 1:Right; 2:Back; 3:Left
- local Heading = {x=0,y=0,z=0}
- local Query
- local IsFull = false
- function MoveUp(amount)
- if (amount<0) then amount=amount*-1 end
- if (amount==0) then return end
- for i=1,amount,1 do
- turtle.digUp()
- if (turtle.up()) then
- y=y+1
- end
- end
- end
- function MoveDown(amount)
- if (amount<0) then amount=amount*-1 end
- if (amount==0) then return end
- for i=1,amount,1 do
- turtle.digDown()
- if (turtle.down()) then
- y=y-1
- end
- end
- end
- function MoveForward(amount)
- if (amount<0) then amount=amount*-1 end
- if (amount==0) then return end
- for i=1,amount,1 do
- turtle.dig()
- if (turtle.forward()) then
- if (Orien==0)then
- z=z-1
- elseif (Orien==1)then
- x=x+1
- elseif (Orien==2)then
- z=z+1
- elseif (Orien==3)then
- x=x-1
- end
- end
- end
- end
- function SetFacing(direction)
- while(true) do
- if (direction==Orien) then
- break
- end
- if (turtle.turnRight()) then
- Orien = Orien+1
- if (Orien>3) then Orien=0 end
- end
- end
- end
- function Movement()
- --X
- if (x>Heading.x) then
- SetFacing(3)
- elseif (x<Heading.x) then
- SetFacing(1)
- end
- MoveForward(Heading.x - x)
- --Y
- if (y>Heading.y) then
- MoveUp(Heading.y - y)
- elseif (y<Heading.y) then
- MoveDown(Heading.y - y)
- end
- --Z
- if (z>Heading.z) then
- SetFacing(0)
- elseif (z<Heading.z) then
- SetFacing(2)
- end
- MoveForward(Heading.z - z)
- end
- function Search()
- turtle.select(2)
- turtle.equipRight() --Equip scanner
- local Scanner = peripheral.wrap("right")
- local scan = Scanner.scan(16)
- if (scan ~= nil) then
- for i, data in ipairs(scan) do
- if (string.match(data.name, Query)) then
- Heading.x = data.x+x
- Heading.y = data.y+y
- Heading.z = data.z+z
- break
- end
- end
- end
- turtle.select(2)
- turtle.equipRight(2) --UnEquip scanner
- turtle.select(1) --Equip bucket
- end
- function Refuel()
- turtle.select(1) --Equip bucket
- local success, data = turtle.inspect()
- if (success and data.name=="minecraft:lava") then
- turtle.place()
- end
- success, data = turtle.inspectUp()
- if (success and data.name=="minecraft:lava") then
- turtle.placeUp()
- end
- success, data = turtle.inspectDown()
- if (success and data.name=="minecraft:lava") then
- turtle.placeDown()
- end
- end
- function Inventory()
- --1 and 2 are the bucket and the scanner, so DON'T drop them
- IsFull = true
- for i=3,16,1 do
- local data = turtle.getItemDetail(i)
- if (string.match(data.name, Query)~=false) then
- turtle.select(i)
- turtle.drop()
- IsFull = false
- end
- end
- turtle.select(1) --Equip bucket
- end
- function GoHome()
- local FuelNeeded = math.floor((x+y+z)*2.5) -- Imagine is a straight line and then think it has to dig all the way
- if (turtle.getFuelLevel()<=FuelNeeded or ISFull==true) then
- Heading.x=0
- Heading.y=0
- Heading.z=0
- Movement()
- return true
- end
- return false
- end
- -- Main --
- term.setTextColor(colors.green)
- term.write("Instructions: Place a bucket in the first slot, then a geo scanner in the seccond, then equip a pickaxe on the right side and a chunk loader on the left.")
- term.setTextColor(colors.cyan)
- term.write("Search for: ")
- Query = read()
- while(true) do
- term.clear()
- term.setCursorPos(1,1)
- term.write(Query .. " at: " .. Heading.x .. " " .. Heading.y .. " " .. Heading.z)
- if (GoHome()==false) then
- Search()
- Movement()
- Refuel()
- Inventory()
- else
- term.clear()
- term.setCursorPos(1,1)
- term.write("Heading home.")
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement