Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("turtle")
- facing = "east"
- rightTurnsFromTo = {
- north = {north=0, east=1, south=2, west=3},
- east = {north=3, east=0, south=1, west=2},
- south = {north=2, east=3, south=0, west=1},
- west = {north=1, east=2, south=3, west=0},
- }
- function tprint(tbl)
- for i,v in pairs(tbl) do
- print(i, v)
- end
- end
- function block1()
- --scan and mine all blocks around
- --use gps
- if turtle.getFuelLevel() < 100 then
- error("needs more fuel")
- end
- turtle.select(16)
- turtle.digDown()
- turtle.placeDown()
- sleep(3)
- tprint(peripheral.getNames())
- tprint(peripheral.getMethods("bottom"))
- scanner = peripheral.wrap("bottom")
- if not scanner then
- error("peripheral wrap bottom failed")
- end
- blocks = scanner.scan(8)
- if not blocks then
- error("scanner failed to scan")
- end
- turtle.select(16)
- turtle.digDown()
- end
- function block2()
- function filter(blocks, needle)
- output = {}
- for i,v in pairs(blocks) do
- if v.name:find(needle) then
- output[#output+1] = v
- end
- end
- return output
- end
- ores = filter(blocks,"dirt")
- for i,v in pairs(ores) do
- print(v.name, v.x, v.y, v.z)
- end
- end
- function block3()
- function digToXZ(dT, dirIfGt0, dirIfLt0)
- rightTurns = 0
- if dT > 0 then
- rightTurns = rightTurnsFromTo[facing][dirIfGt0]
- temp = dirIfLt0
- elseif dT < 0 then
- rightTurns = rightTurnsFromTo[facing][dirIfLt0]
- temp = dirIfGt0
- end
- for i=1,rightTurns do
- turtle.turnRight()
- end
- facing = temp
- for i=1,math.abs(dT) do
- turtle.dig()
- turtle.forward()
- end
- end
- function digToY(dy)
- if dy > 0 then
- for i=1,dy do
- turtle.up()
- end
- elseif dy < 0 then
- for i=1,math.abs(dy) do
- turtle.down()
- end
- end
- end
- function digTo(dx,dy,dz,dir)
- digToXZ(dx, "east", "west")
- digToXZ(dz, "south", "north")
- digToY(dy)
- end
- for i,block in pairs(ores) do
- x,y,z = gps.locate()
- dx = x + block.x
- dy = y + block.y
- dz = z + block.z
- digTo(dx,dy,dz,facing)
- end
- end
- block1()
- block2()
- block3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement