Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- QuarryBot (1.0)
- -- REQUIRES
- local robot = require( "robot" )
- local term = require( "term" )
- local event = require( "event" )
- local component = require( "component" )
- -- LOCAL VARIABLES
- local chunksWide = 1
- local chunksDeep = 1
- local level = 0
- local shovelSlot = 0
- local chestSlot = 0
- local inventory = false
- -- filters are items not to dig from walls
- -- shovelFilters are items to shovel if digging down, but not from walls
- local firstFilter = 0
- local firstShovelFilter = 0
- local lastFilter = 0
- -- INITIALIZATION FUNCTIONS
- local function loadItem( item, slot )
- print( "Shift-click "..item.." into slot 1..." )
- event.pullFiltered( function( name, slot ) return name == "inventory_changed" and slot == 1 and robot.count( 1 ) > 0 end )
- robot.transferTo( slot )
- end
- local function initItems()
- term.clear()
- term.setCursor( 1, 1 )
- robot.select( 1 )
- print("QuarryBot v1.0")
- if component.isAvailable("inventory_controller") then
- print( "Inventory Manager found!\n" )
- inventory = component.inventory_controller
- shovelSlot = robot.inventorySize()
- chestSlot = shovelSlot - 1
- loadItem( "pickaxe into tool slot then shovel", shovelSlot )
- loadItem( "ender chest", chestSlot )
- else
- print( "Inventory Manager not found." )
- print( "Shovel equip disabled.\n" )
- chestSlot = robot.inventorySize()
- loadItem( "pickaxe into tool slot then ender chest", chestSlot )
- end
- end
- local function initFilters()
- lastFilter = chestSlot - 1
- firstShovelFilter = lastFilter + 1
- if inventory ~= false then
- print( "Shift click in all shoveled items (dirt, etc.)" )
- print( "Press space when done..." )
- while true do
- ev, slot, key = event.pull()
- if ev == "inventory_changed" and slot == 1 and robot.count( 1 ) > 0 then
- firstShovelFilter = firstShovelFilter - 1
- robot.transferTo( firstShovelFilter )
- elseif ev == "key_down" and key == string.byte( " " ) then
- break
- end
- end
- print( "Shift click in all other filtered items (stone, etc.)" )
- else
- print( "Shift click in all filtered items (stone, dirt, etc.)" )
- end
- print( "Press space when done..." )
- firstFilter = firstShovelFilter
- while true do
- ev, slot, key = event.pull()
- if ev == "inventory_changed" and slot == 1 and robot.count( 1 ) > 0 then
- firstFilter = firstFilter - 1
- robot.transferTo( firstFilter )
- elseif ev == "key_down" and key == string.byte( " " ) then
- break
- end
- end
- end
- local function isFull()
- for i = 1, firstFilter - 1 do
- if robot.count( i ) == 0 then
- return false
- end
- end
- return true
- end
- local placeFunc = { [1] = robot.place, [2] = robot.placeDown }
- local swingFunc = { [1] = robot.swing, [2] = robot.swingDown }
- local dropFunc = { [1] = robot.drop, [2] = robot.dropDown }
- local function unload( direction )
- print( "Unloading" )
- robot.select( chestSlot )
- if placeFunc[direction]() then
- for i = 1, firstFilter - 1 do
- robot.select( i )
- dropFunc[direction]()
- end
- for i = firstFilter, lastFilter do
- robot.select( i )
- dropFunc[direction]( robot.count( i ) - 1 )
- end
- robot.select( chestSlot )
- swingFunc[direction]()
- else
- print( "Could not place chest" )
- end
- robot.select( 1 )
- end
- -- Break block if not blacklisted
- local function digWall()
- for i = firstFilter, lastFilter do
- robot.select( i )
- if robot.compare() then return end
- end
- robot.select( 1 )
- robot.swing()
- if isFull() then
- unload( 1 )
- end
- end
- local function digDown()
- if robot.detectDown() then
- if inventory ~= false then
- for i = firstShovelFilter, lastFilter do
- robot.select( i )
- if robot.compareDown() then
- robot.select( shovelSlot )
- inventory.equip()
- robot.select( 1 )
- robot.swingDown()
- robot.select( shovelSlot )
- inventory.equip()
- if isFull() then
- unload( 2 )
- end
- return
- end
- end
- end
- robot.select( 1 )
- if robot.swingDown() and isFull() then
- unload( 2 )
- end
- end
- end
- local function down()
- digDown()
- if not robot.down() then
- return false
- end
- return true
- end
- local function digHole()
- level = 0
- while down() do
- digWall()
- level = level + 1
- end
- robot.turnAround()
- for i = 1, level do
- digWall()
- tries = 0
- while not robot.up() do
- tries = tries + 1
- if tries > 2 then
- print( "Stopping due to 3rd up failure" )
- os.exit()
- end
- print( "Couldn't go up on try: ", tries)
- end
- end
- robot.turnAround()
- end
- -- Initialize
- initItems()
- initFilters()
- term.clear()
- term.setCursor( 1, 1 )
- print( "First Filter Slot: ", firstFilter )
- print( "First Shovel Filter Slot: ", firstShovelFilter )
- print( "Last Filter Slot: ", lastFilter )
- print()
- print( "Mining!!!" )
- local turnFunc = { [true] = robot.turnRight, [false] = robot.turnLeft }
- local turningRight = true
- for width = 1, chunksWide * 16 do
- for depth = 1, chunksDeep * 16 / 3 do
- if depth ~= 1 then
- for i = 1, 3 do
- if not robot.forward() then
- robot.swing()
- robot.forward()
- end
- end
- end
- digHole()
- end
- turnFunc[turningRight]()
- robot.forward()
- turnFunc[turningRight]()
- turningRight = not turningRight
- end
Advertisement
Add Comment
Please, Sign In to add comment