MiningRigControl

Mirror of http://pastebin.com/rNwqH66u

--MiningRig control
d = "right"
failcount = 0

function dig()
  rs.setBundledOutput(d,colors.orange)
  os.sleep(8)
  rs.setBundledOutput(d,0)
end

function move()
  rs.setBundledOutput(d,colors.magenta)
  os.sleep(2)
  rs.setBundledOutput(d,colors.lightBlue)
  os.sleep(2)
  rs.setBundledOutput(d,0)
end

function breakBlocks()
  rs.setBundledOutput(d,colors.white)
  os.sleep(0.5)
  rs.setBundledOutput(d,0)
  os.sleep(0.5)
end

function checkChest()
  c = peripheral.wrap("top")
  if c.getStackInSlot(1) == nil then
    return false
  else
    return true
  end     
end


while true do
--for i=1,2 do 
  
  if turtle.getFuelLevel() < 10 then
    break
  end
  
  --check if too far
  if rs.getInput("right") == true then
    turtle.back()
    print("Move operation unsuccessful...")
    os.sleep(1)
    failcount = failcount + 1
    --os.sleep(60)
    --break
  else
    failcount = 0
  end
  
  if failcount > 3 then
    break
  end
  
  
  --place ender chest
  turtle.placeUp()
  if checkChest() == true then
    breakBlocks()
    print("Stuff in chest! Mining...")
    --pickup ender chest
    turtle.digUp()
    dig()
    breakBlocks()
    move()
    breakBlocks()
    
    if turtle.detect() == true then
      turtle.dig()
      turtle.select(2)
      turtle.dropDown()
      turtle.select(1)
    end
    
    turtle.forward()  
    
    if turtle.detectUp() == true then
      turtle.digUp()
      turtle.select(2)
      turtle.dropDown()
      turtle.select(1)
    end
    os.sleep(1)
           
  else
    print("Nothing in chest waiting...")
    os.sleep(10)
  end

end
Advertisements