Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local FUEL = true
- local NUM_STRIPS = 32
- local STRIP_DISTANCE = 3
- local GRAVEL_FALL_TIME = 0.5
- local ENDERCHEST_FAIL_WAIT_TIME = 0.5
- local SLOT_ENDERCHEST_ITEMS = 1
- local SLOT_ENDERCHEST_FUEL = 2
- local SLOT_MINING = 2
- local yieldTime -- variable to store the time of the last yield
- local function yield()
- if yieldTime then -- check if it already yielded
- if os.clock() - yieldTime > 2 then -- if it were more than 2 seconds since the last yield
- os.queueEvent("someFakeEvent") -- queue the event
- os.pullEvent("someFakeEvent") -- pull it
- yieldTime = nil -- reset the counter
- end
- else
- yieldTime = os.clock() -- store the time
- end
- end
- function mine1()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(GRAVEL_FALL_TIME)
- end
- while turtle.detect() do
- turtle.dig()
- sleep(GRAVEL_FALL_TIME)
- end
- turtle.digDown()
- while not turtle.forward() do
- turtle.dig()
- sleep(GRAVEL_FALL_TIME)
- end
- end
- function mine1row()
- for i=1,45 do
- mine1()
- yield()
- end
- end
- function mine2rows()
- mine1row()
- turtle.turnLeft()
- for i=1,STRIP_DISTANCE do
- mine1()
- yield()
- end
- turtle.turnLeft()
- mine1row()
- end
- function mineFull(length)
- for i=1,length do
- turtle.select(2)
- turtle.turnRight()
- mine2rows()
- turtle.turnRight()
- if FUEL then
- if turtle.getFuelLevel() < 140 then
- print "Need fuel ..."
- end
- -- Refuel
- while turtle.getFuelLevel() < 140 do
- turtle.select(SLOT_ENDERCHEST_FUEL)
- turtle.digDown() -- Note: Not testing for unmineable blocks.
- turtle.placeDown()
- turtle.suckDown()
- turtle.refuel()
- turtle.digDown()
- sleep(10)
- end
- end
- print("Continuing row ", i)
- for i=1,STRIP_DISTANCE do
- mine1()
- yield()
- end
- turtle.back()
- turtle.select(SLOT_ENDERCHEST_ITEMS)
- while not turtle.place() do -- Place down enderchest
- turtle.dig()
- end
- for j=2,10 do
- turtle.select(j)
- -- Wait if cannot place in enderchest
- while not turtle.drop() and turtle.getItemCount(j) > 0 do
- print "Enderchest full... waiting to empty slots 2-10"
- sleep(ENDERCHEST_FAIL_WAIT_TIME)
- end
- yield()
- end
- sleep(1) -- Allow time to empty enderchest
- for j=11,16 do
- turtle.select(j) -- Place remaining 6 slots into enderchest
- while not turtle.drop() and turtle.getItemCount(j) > 0 do
- print "Enderchest full... waiting to empty slots 11-16"
- sleep(ENDERCHEST_FAIL_WAIT_TIME)
- end
- yield()
- end
- turtle.select(SLOT_ENDERCHEST_ITEMS)
- turtle.dig() -- Pick up enderchest
- while turtle.detect() do
- turtle.dig()
- yield()
- end
- turtle.forward()
- yield()
- end
- end
- function mineReturn()
- mineFull(NUM_STRIPS)
- turtle.turnRight()
- turtle.turnRight()
- totalDistance = NUM_STRIPS * STRIP_DISTANCE * 2
- for i=1,totalDistance do
- mine1()
- yield()
- end
- end
Add Comment
Please, Sign In to add comment