Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- -- overall tunnel length
- local LENGTH = tonumber(args[1])
- if not LENGTH then print('usage: \'stripmine <length:int> [<throwaway:string>, ...]\'') return end
- -- throwaway items
- local THROWAWAY = args
- for i = 2, #args do
- THROWAWAY['minecraft:' .. args[i]] = true
- end
- local name = os.getComputerLabel()
- local CURRENT = 0
- os.setComputerLabel(name .. ': Strip Mining')
- local drop = function()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemDetail() and THROWAWAY[turtle.getItemDetail().name] then
- turtle.drop()
- end
- end
- end
- local torch = function()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getItemDetail() and turtle.getItemDetail().name == 'minecraft:torch' then
- turtle.turnRight()
- turtle.placeUp()
- turtle.turnLeft()
- return true
- end
- end
- return false
- end
- local refuel = function()
- local fuel = turtle.getFuelLevel()
- if fuel > 1 then
- return true
- end
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel(math.ceil(turtle.getItemCount(i) / 2))
- return true
- end
- end
- return false
- end
- local return_origin = function()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, CURRENT do
- turtle.forward()
- refuel()
- end
- end
- local dig = function()
- if turtle.detect() then
- local success, data = turtle.inspect()
- if success then
- if data.name == 'minecraft:diamond_ore' then
- return true
- end
- end
- turtle.dig()
- end
- return false
- end
- local found
- while CURRENT < LENGTH do
- if not refuel() then
- print('program terminated: not enough fuel')
- os.setComputerLabel(name)
- return
- end
- -- dig lower block
- found = dig()
- if found then break end
- -- dig upper block
- turtle.up()
- found = dig()
- if found then turtle.down(); break end
- -- reset turtle, check if we need to place a torch and move forward
- turtle.down()
- if CURRENT % 10 == 1 then
- if not torch() then
- print('program terminated: not enough torches')
- break
- end
- end
- turtle.forward()
- drop()
- CURRENT = CURRENT + 1
- end
- return_origin()
- if found then
- os.setComputerLabel(name .. ': Found Diamond!')
- print('Found diamonds at xxxyyy!')
- else
- os.setComputerLabel(name .. ': Finished!')
- end
- print('Press any key to return to CraftOS...')
- os.pullEventRaw('key')
- os.setComputerLabel(name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement