Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local length = 160
- local width = 160
- local mining = true
- local l = 0
- local w = 0
- local clean = 32
- local clean_count = 0
- local turn = 1--1=>right,-1=>left
- --fuel is first slot
- --then important blocks
- --then inventory
- --overlapping is undefined (except fuel slot being important)
- --gaps are undefined (except btwn important_end and inven_start, blocks there will be collected but only up to one stack)
- local fuel = 1
- local important_start = 1
- local important_end = 3
- local inven_start = important_end+1
- local inven_end = 16
- function refuel()--returns false if it ran out of coal and has low energy
- if turtle.getFuelLevel() < 3 then
- if turtle.getItemCount(1) <= 1 then
- return false
- else
- print("Refueling")
- turtle.refuel(1)
- print("new fuel level: "..turtle.getFuelLevel())
- print("remaing fuel: "..turtle.getItemCount(1))
- return true
- end
- end
- return true
- end
- function dig_forward()--returns if it can dig and move forward
- while turtle.detect() do
- turtle.dig()
- end
- local rtn = turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- end
- while turtle.detectDown() do
- turtle.digDown()
- end
- return rtn
- end
- function clean_inventory()--returns false if inventory is full of important blocks
- local full = 0
- local selected = turtle.getSelectedSlot()
- for i=inven_start,inven_end do
- turtle.select(i)
- drop = true
- for i=important_start,important_end do
- if turtle.compareTo(i) then
- drop = false
- end
- end
- if drop then
- turtle.drop()
- end
- if turtle.getItemSpace(i) == 0 then
- full = full+1
- end
- end
- turtle.select(selected)
- if full >= inven_end - inven_start + 1 then
- return false
- else
- return true
- end
- end
- while mining do
- dig_forward()
- l = l+1
- if l>length then
- if turn > 0 then
- turtle.turnRight()
- dig_forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- dig_forward()
- turtle.turnLeft()
- end
- turn = turn*-1
- l = 0
- w = w+1
- if w > width then
- print("End or route")
- w = 0
- mining = false
- end
- end
- if clean_count >= clean then
- if not clean_inventory() then
- print("Inventory full")
- mining = false
- end
- clean_count = 0
- else
- clean_count = clean_count + 1
- end
- if not refuel() then
- print("out of fuel")
- mining = false
- end
- end
Add Comment
Please, Sign In to add comment