Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dist = 0 --unused
- local x = 0
- local y = 0
- local height = 0
- local inc_x = 1
- local inc_y = 1
- local thickness = 1
- local direction = 0
- local inc = 1
- local ignores = 0
- while tonumber(ignores)<=0 do --ignore value definition
- print("please indicate how many slots should be ignore markers, cannot be less than 1")
- ignores = read()
- end
- local ignore = tonumber(ignores)
- term.clear()
- function mineOre() --modified vein miner by GOPHER ATL
- local function doMine(digFunc, moveFunc, backFunc, compareFunc, detectFunc)
- if not smartcompare(compareFunc,detectFunc) then
- return
- end
- digFunc()
- moveFunc()
- for i=1,4 do
- goLeft()
- if turtle.detect() then
- doMine(turtle.dig,digforw,turtle.back,turtle.compare, turtle.detect)
- end
- end
- if turtle.detectUp() then
- doMine(digup, turtle.up, turtle.down, turtle.compareUp, turtle.detectUp)
- end
- if turtle.detectDown() then
- doMine(digdown, turtle.down, turtle.up, turtle.compareDown, turtle.detectDown)
- end
- backFunc()
- return
- end
- doMine(turtle.dig,digforw,turtle.back, turtle.compare, turtle.detect)
- end
- function bridge() --unused
- if turtle.detectDown()~=true then
- turtle.select(2)
- turtle.placeDown()
- end
- end
- function dump(pos) --dump items to ender chest in slot 1
- if pos==Up then
- if turtle.getItemCount(16)>0 then
- turtle.digUp()
- turtle.select(1)
- turtle.placeUp()
- for slotn = 4, ignore do
- for slot = 3+ignore,16,1 do
- turtle.select(slot)
- if turtle.compareTo(slotn) then
- turtle.dropDown()
- end
- turtle.dropUp()
- end
- end
- turtle.select(1)
- turtle.digUp()
- end
- elseif pos==Down then
- if turtle.getItemCount(16)>0 then
- turtle.digDown()
- turtle.select(1)
- turtle.placeDown()
- for slotn = 4, ignore do
- for slot = 3+ignore,16 do
- turtle.select(slot)
- if turtle.compareTo(slotn) then
- turtle.dropUp()
- turtle.dropDown()
- end
- end
- turtle.select(1)
- turtle.digDown()
- end
- end
- end
- end
- function digforw() --anti-gravel and mob forward digging
- while turtle.detect() do
- turtle.dig()
- end
- while not turtle.forward() do
- turtle.attack()
- end
- dist = dist + 1
- record()
- display()
- end
- function goback() --anti-mob backwards digging
- while not turtle.back() do
- attackBack()
- end
- record(backrecorder)
- display()
- end
- function attackBack() --for goback()
- local d = true
- turtle.turnLeft()
- turtle.turnLeft()
- while d == true do
- d = turtle.attack()
- sleep(0.5)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function smartcompare(compareFunc, detectFunc) --compare block to items in slot 4-ignore value
- local memory = 0
- for cslot = 4, 3 + ignore do
- turtle.select(cslot)
- if (not compareFunc(cslot))and detectFunc() then
- memory = memory + 1
- else
- print("false")
- return false
- end
- if memory >= ignore then
- print(ignore)
- print("true")
- return true
- end
- end
- end
- function check() --analyze the block, if not recognized then dig the vein
- if smartcompare(turtle.compare, turtle.detect) then
- print("mining vein...")
- mineOre()
- sleep(1)
- return true
- else
- return false
- end
- end
- function checkOre(digDirFunc) --turn around checking for ores
- digDirFunc()
- local count = 0
- for dir = 1, 4 do
- if check() then
- count = count + 1
- end
- goLeft()
- end
- if count > 0 then
- return true
- else
- return false
- end
- end
- function checkforw() --check and go forward at the same time
- digforw()
- for dir = 1, 4 do
- check()
- goLeft()
- end
- local recoverDown = 0
- while smartcompare(turtle.compareDown, turtle.detectDown) do
- checkOre(digdown)
- recoverDown = recoverDown + 1
- end
- for l = 1, recoverDown do
- digup()
- end
- digup()
- for dir = 1, 4 do
- check()
- goLeft()
- end
- while smartcompare(turtle.compareUp, turtle.detectUp) do
- checkOre(digup)
- end
- digdown()
- end
- function goRight() --turn right while registering the direction
- turtle.turnRight()
- if direction < 3 then
- direction = direction + 1
- else
- direction = 0
- end
- end
- function goLeft() --turn left while reg. the direction
- turtle.turnLeft()
- if direction > 0 then
- direction = direction - 1
- else
- direction = 3
- end
- end
- function digup() --anti-gravel and mob upward dig
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.4)
- end
- while not turtle.up() do
- turtle.attackUp()
- end
- dump("Down")
- end
- function digdown() --anti-gravel and mob downward dig
- while turtle.detectDown() do
- turtle.digDown()
- end
- while not turtle.down() do
- turtle.attackDown()
- end
- dump("Up")
- end
- function torch() --unused
- if dist >= 12 then
- turtle.select(2)
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.placeUp()
- dist = 0
- end
- end
- function refuel() --auto refuel on slot 3
- if turtle.getFuelLevel() <= 512 then
- turtle.select(3)
- turtle.refuel(4)
- end
- end
- function record(recordFunc) --records the coordinates
- if recordFunc == nil then
- recordFunc = recorder
- end
- if direction == 0 then
- inc_y = 1
- inc_x = 0
- elseif direction == 1 then
- inc_y = 0
- inc_x = 1
- elseif direction == 2 then
- inc_y = -1
- inc_x = 0
- elseif direction == 3 then
- inc_y = 0
- inc_x = -1
- end
- recordFunc()
- end
- function recorder() --two different recorders for forwards and backwards
- x = x+inc_x
- y = y+inc_y
- end
- function backrecorder()
- x = x-inc_x
- y = y-inc_y
- end
- function straighten() --faces direction 0
- local _direction = direction
- for turn = 1, _direction do
- goLeft()
- end
- direction = 0
- end
- function homeX(target_x) --moves to the targeted x and y
- print("adjusting X to home in")
- straighten()
- if target_x < x then
- goLeft()
- elseif target_x > x then
- goRight()
- end
- for nudgeX = 1, math.abs(target_x - x) do
- digforw()
- end
- end
- function homeY(target_y)
- print("adjusting Y to home in")
- straighten()
- if target_y < y then
- goLeft()
- goLeft()
- end
- for nudgeY = 1, math.abs(target_y - y) do
- digforw()
- end
- end
- --debug
- function display() --displays positional data to terminal
- term.clear()
- term.setCursorPos(1,1)
- print("x relative to the starting point is: "..x)
- print("z relative to the starting point is: "..y)
- print("the direction is: "..direction)
- end
- term.clear() --start of the program
- term.setCursorPos(2,2)
- print("please enter the thickness")
- inc = read()
- term.clear()
- term.setCursorPos(2,2)
- print("please enter the radius (the number of circles)")
- local diam = read()
- local I = tonumber(diam)/2
- local i = 0
- repeat
- for length = 1,thickness do
- dump("Up")
- checkforw()
- end
- refuel()
- thickness = thickness + math.floor(inc)
- goRight()
- display()
- i = i + 0.25
- until i == I
- homeX(0)
- homeY(0)
- dump("Up")
Advertisement
Add Comment
Please, Sign In to add comment