Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local centralLoc = {x=-149,y=8,z=-85}
- --local base1 =
- local dumpChestLoc = {x=-147, y=6, z=-97}
- local fuelChestLoc = {x=-147, y=6, z=-99}
- local bombChestLoc = {x=-147, y=6, z=-101}
- --local ????ChestLoc = {x=-147, y=6, z=-103}
- local max = 16
- function main()
- end
- function locate()
- x0, y0, z0 = gps.locate()
- if x0==nil or y0==nil or z0==nil then
- print("error locating")
- os.sleep(4)
- return locate()
- end
- return {x=x0,y=y0,z=z0}
- end
- function dig()
- if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
- turtle.select(16)
- if turtle.compare() then
- turtle.digUp()
- turtle.up()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
- moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
- end
- turtle.dig()
- end
- function digDown()
- if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
- if turtle.compareDown() then
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
- moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
- end
- turtle.digDown()
- end
- function digUp()
- if turtle.getSelectedSlot ~= 16 then turtle.select(16) end
- if turtle.compareUp() then
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- moveTo({y=centralLoc.y, z=centralLoc.z}, 1)
- moveTo({x=centralLoc.x, y=centralLoc.y, z=centralLoc.z}, 1)
- end
- turtle.digUp()
- end
- function vertN(n, agg)
- if n<0 then
- for i=1,-n do
- if turtle.detectDown() then
- if agg then
- digDown()
- else
- return true
- end
- end
- turtle.down()
- end
- end
- if n>0 then
- for i=1,n do
- if turtle.detectUp() then
- if agg then
- digUp()
- else
- return true
- end
- end
- turtle.up()
- end
- end
- end
- function forwardN(n, agg)
- for i=1,n do
- if turtle.detect() then
- if agg then
- dig()
- else
- return true
- end
- end
- turtle.forward()
- end
- return false
- end
- function orientNorth(agg)
- if turtle.detect() then
- turtle.turnRight()
- end
- if turtle.detect() then
- turtle.turnRight()
- end
- if turtle.detect() then
- turtle.turnRight()
- end
- if turtle.detect() then
- if agg then
- dig()
- else
- return true
- end
- end
- local pos1 = locate()
- turtle.forward()
- local pos2 = locate()
- turtle.back()
- if pos1.z-1==pos2.z then
- return false
- elseif pos1.x+1==pos2.x then
- turtle.turnLeft()
- return false
- elseif pos1.z+1==pos2.z then
- turtle.turnLeft()
- turtle.turnLeft()
- return false
- elseif pos1.x-1==pos2.x then
- turtle.turnRight()
- return false
- end
- return true
- end
- function moveDelta(delta, agg)
- -- turn north (return error otherwise)
- if orientNorth(agg) then
- return true
- end
- -- move y direction
- vertN(delta.y, agg)
- -- move z direction
- if delta.z<0 then
- forwardN(-delta.z, agg)
- elseif delta.z>0 then
- turtle.turnLeft()
- turtle.turnLeft()
- forwardN(delta.z, agg)
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- move x direction
- if delta.x<0 then
- turtle.turnLeft()
- forwardN(-delta.x, agg)
- turtle.turnRight()
- elseif delta.x>0 then
- turtle.turnRight()
- forwardN(delta.x, agg)
- turtle.turnLeft()
- end
- end
- function moveTo(loc, agg)
- -- determine location
- local here = locate()
- -- assign any unassigned locations
- if loc.x == nil then loc.x = here.x end
- if loc.y == nil then loc.y = here.y end
- if loc.z == nil then loc.z = here.z end
- -- create delta vector
- local delta = {x=loc.x-here.x,y=loc.y-here.y,z=loc.z-here.z}
- if delta.x == 0 and delta.y == 0 and delta.z == 0 then
- return
- end
- -- any values above max reduce
- if ( delta.x > max) then delta.x = max end
- if (-delta.x > max) then delta.x = -max end
- if ( delta.y > max) then delta.y = max end
- if (-delta.y > max) then delta.y = -max end
- if ( delta.z > max) then delta.z = max end
- if (-delta.z > max) then delta.z = -max end
- moveDelta(delta, agg)
- -- recurse to finish
- moveTo(loc, agg)
- end
- function inventorySpace()
- local count = 0
- for i=1,16 do
- if turtle.getItemCount() == 0 then
- count = count + 1
- end
- end
- return count
- end
- function alignX(agg, max)
- --local loc = locate()
- --moveTo({x=centralLoc.x,y=loc.y,z=loc.z}, agg, max)
- --moveTo({x=centralLoc.x}, agg, max)
- end
- function dropAll()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function emptyInventory(agg)
- moveTo({x=centralLoc.x}, agg)
- moveTo(dumpChestLoc, agg)
- orientNorth()
- turtle.turnRight()
- dropAll()
- end
- function setInventory(num, agg)
- emptyInventory(agg)
- if num == 0 then
- moveTo(bombChestLoc, 0)
- turtle.turnRight()
- turtle.select(16)
- turtle.suck()
- end
- end
- function strip(loc, length)
- setInventory(0, 0)
- moveTo(loc, 0)
- moveTo({loc.x-length, loc.y, loc.z}, 1)
- moveTo(loc, 1)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement