Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filter="applied"
- meta=0
- scanner=peripheral.wrap("back")
- function getAngle(x,y)
- return (180/math.pi)*math.atan(y,x)
- end
- function getDistance(block)
- vec=vector.new(block.x,block.y,block.z)
- return vec.length(vec)
- end
- function moveTo(x,y,z)
- if x~=0 then
- xa=0
- if x>0 then xa=-90 elseif x<0 then xa=90 end
- scanner.launch(xa,0,0.2)
- end
- if z~=0 then
- xa=0
- if z>0 then xa=0 elseif z<0 then xa=180 end
- scanner.launch(xa,0,0.2)
- end
- end
- while true do
- blocks={}
- for _, block in pairs(scanner.scan()) do
- if string.find(block.name,filter) and block.metadata==meta then
- table.insert(blocks,block)
- end
- end
- table.sort(blocks,function(a,b) return getDistance(a)<getDistance(b) end)
- if #blocks>0 then
- block=blocks[1]
- msg=(("The block at %d, %d, %d is %s"):format(block.x, block.y, block.z, block.name))
- scanner.tell(msg)
- moveTo(block.x,block.y,block.z)
- print(msg)
- end
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement